bayes_pol

Submodules

bayes_pol.faraday_model

faraday_model.py FaradayModel definition

Copyright(C) 2025 by Trey V. Wenger; tvwenger@gmail.com This code is licensed under MIT license (see LICENSE for details)

class bayes_pol.faraday_model.FaradayModel(*args, lam2_window_width=None, **kwargs)

Bases: BaseModel

Definition of the model

Attributes:
baseline_deterministics

Get the deterministic baseline parameter names.

baseline_freeRVs

Get the free baseline parameter names.

cloud_deterministics

Get the deterministic cloud parameter names.

cloud_freeRVs

Get the free cloud parameter names.

hyper_deterministics

Get the deterministic hyper parameter names.

hyper_freeRVs

Get the free hyper parameter names.

labeller

Get the arviz labeller.

unique_solution

Check if posterior samples suggest a unique solution.

Methods

add_baseline_priors([prior_baseline_coeffs])

Add baseline priors to the model.

add_likelihood()

Add likelihood to the model.

add_priors([prior_polarized_intensity, ...])

Add priors and deterministics to the model

bic([chain, solution])

Calculate the Bayesian information criterion at the mean point estimate.

fit([n, draws, rel_tolerance, ...])

Approximate posterior distribution using Variational Inference (VI).

graph()

Generate visualization of the model graph.

mean_lnlike([chain, solution])

Evaluate mean log-likelihood over posterior samples.

null_bic()

Evaluate the Bayesian Information Criterion for the null hypothesis (baseline only, no clouds)

predict_baseline([baseline_params])

Predict the un-normalized baseline model.

reset_results()

Reset results and convergence checks.

sample([init, n_init, chains, init_kwargs, ...])

Sample posterior distribution using MCMC.

sample_posterior_predictive([solution, thin])

Generate posterior predictive samples

sample_prior_predictive([samples])

Generate prior predictive samples

sample_smc(**kwargs)

Sample posterior distribution using Sequential Monte Carlo.

solve([num_gmm_samples, kl_div_threshold])

Identify unique solutions and break the labeling degeneracy.

add_likelihood()

Add likelihood to the model. SpecData key must be “Q”, “U”, and “faraday_depth_abs”. Spectral units for “Q” and “U” should be square wavelength in m2. Spectral units for “faraday_depth_abs” should be rad/m2. Order of clouds is nearest to farthest.

add_priors(prior_polarized_intensity: float = 100.0, prior_faraday_depth_mean: float = [0.0, 1000.0], prior_faraday_depth_fwhm: float = 10.0)

Add priors and deterministics to the model

Parameters:
prior_polarized_intensityfloat, optional

Prior distribution on the polarized intensity (data brightness), by default 100.0, where polarized_intensity ~ HalfNormal(sigma=prior)

prior_faraday_depth_meanIterable[float], optional

Prior distribution on the mean Faraday depth (rad/m2), by default [0.0, 1000.0], where faraday_depth_mean ~ Cauchy(alpha=prior[0], beta=prior[1])

prior_faraday_depth_fwhmfloat, optional

Prior distribution on the Faraday depth full-width at half-maximum (rad/m2), by default 10.0, where faraday_depth_fwhm ~ HalfNormal(sigma=prior)

bayes_pol.faraday_model.sinc(x: float) float

Evaluate sin(x)/x and catch x=0.

Parameters:
xfloat

Position at which to evaluate

Returns:
float

sin(x)/x

Module contents

class bayes_pol.FaradayModel(*args, lam2_window_width=None, **kwargs)

Bases: BaseModel

Definition of the model

Attributes:
baseline_deterministics

Get the deterministic baseline parameter names.

baseline_freeRVs

Get the free baseline parameter names.

cloud_deterministics

Get the deterministic cloud parameter names.

cloud_freeRVs

Get the free cloud parameter names.

hyper_deterministics

Get the deterministic hyper parameter names.

hyper_freeRVs

Get the free hyper parameter names.

labeller

Get the arviz labeller.

unique_solution

Check if posterior samples suggest a unique solution.

Methods

add_baseline_priors([prior_baseline_coeffs])

Add baseline priors to the model.

add_likelihood()

Add likelihood to the model.

add_priors([prior_polarized_intensity, ...])

Add priors and deterministics to the model

bic([chain, solution])

Calculate the Bayesian information criterion at the mean point estimate.

fit([n, draws, rel_tolerance, ...])

Approximate posterior distribution using Variational Inference (VI).

graph()

Generate visualization of the model graph.

mean_lnlike([chain, solution])

Evaluate mean log-likelihood over posterior samples.

null_bic()

Evaluate the Bayesian Information Criterion for the null hypothesis (baseline only, no clouds)

predict_baseline([baseline_params])

Predict the un-normalized baseline model.

reset_results()

Reset results and convergence checks.

sample([init, n_init, chains, init_kwargs, ...])

Sample posterior distribution using MCMC.

sample_posterior_predictive([solution, thin])

Generate posterior predictive samples

sample_prior_predictive([samples])

Generate prior predictive samples

sample_smc(**kwargs)

Sample posterior distribution using Sequential Monte Carlo.

solve([num_gmm_samples, kl_div_threshold])

Identify unique solutions and break the labeling degeneracy.

add_likelihood()

Add likelihood to the model. SpecData key must be “Q”, “U”, and “faraday_depth_abs”. Spectral units for “Q” and “U” should be square wavelength in m2. Spectral units for “faraday_depth_abs” should be rad/m2. Order of clouds is nearest to farthest.

add_priors(prior_polarized_intensity: float = 100.0, prior_faraday_depth_mean: float = [0.0, 1000.0], prior_faraday_depth_fwhm: float = 10.0)

Add priors and deterministics to the model

Parameters:
prior_polarized_intensityfloat, optional

Prior distribution on the polarized intensity (data brightness), by default 100.0, where polarized_intensity ~ HalfNormal(sigma=prior)

prior_faraday_depth_meanIterable[float], optional

Prior distribution on the mean Faraday depth (rad/m2), by default [0.0, 1000.0], where faraday_depth_mean ~ Cauchy(alpha=prior[0], beta=prior[1])

prior_faraday_depth_fwhmfloat, optional

Prior distribution on the Faraday depth full-width at half-maximum (rad/m2), by default 10.0, where faraday_depth_fwhm ~ HalfNormal(sigma=prior)