Skip to content

Documentation for CarbonFitter

Parent class of SingleFitter and MultiFitter. Does Monte Carlo sampling, plotting and more.

MarkovChainSampler(params, likelihood, burnin=500, production=1000, k=2, args=())

Runs an affine-invariant MCMC sampler on an array of initial parameters, subject to some likelihood function.

Parameters:

Name Type Description Default
params ndarray

Initial parameters for MC sampler

required
likelihood callable

Log-likelihood function for params

required
burnin int

Number of steps to run in burn-in period. 500 by default.

500
production int

Number of steps to run in production period. 1000 by default.

1000
k

Number of walkers per parameter. 2 by default.

2

Returns:

Type Description
ndarray

A chain of MCMC walk

chain_summary(chain, walkers, figsize=(10, 10), labels=None, plot_dist=False, test_convergence=False, label_font_size=8, tick_font_size=8, mle=False, usetex=False)

Runs convergence tests and plots posteriors from a MCMC chain.

Parameters:

Name Type Description Default
chain ndarray

A MCMC chain

required
walkers int

The total number of walkers of the chain

required
figsize tuple

Output figure size

(10, 10)
labels list[str]

A list of parameter names

None
plot_dist bool

If True, plot the marginal distributions of parameters. Else, plot both the marginal distribution and the posterior surface

False

correlation_plot(array, figsize=10, square_size=100)

Makes an accessible heatmap for visualizing correlation/covariance matrix.

Parameters:

Name Type Description Default
array ndarray

n x n matrix

required
figsize int

Output figure size. 10 by default

10
square_size

Size of squares on the heatmap. 100 by default

100

Returns:

Type Description
figure

heatmap

plot_multiple_chains(chains, walker, figsize=(10, 10), title=None, params_labels=None, labels=None, colors=None, alpha=0.5, linewidths=None, plot_dists=False, label_font_size=12, tick_font_size=8, max_ticks=10, legend=True, usetex=False, truth=None)

Overplots posterior surfaces from multiple chains. Parameters


chains : list List of MCMC chains walker : int Number of walkers for each chain in 'chains' figsize : tuple, optional Output figure size params_labels : list[str], optional List of parameter names labels : list[str], optional List of labels for different chains colors : list[str], optional List of colors alpha : float, optional Parameter for blending, between 0-1. linewidths : float, optional Line width, in points plot_dists : bool, optional If True, only plot the marginal distributions of parameters label_font_size : int, optional Label font size tick_font_size : int, optional Tick font size max_ticks : int, optional Maximum number of ticks allowed legend : bool, optional If True, adds a legend Returns


figure plot of posterior surfaces or marginal distributions