MLE

class tweezepy.MLE.MCMC(walkers=32, steps=1600, progress=True, **kwargs)

Monte Carlo sampler class.

Parameters
  • walkers (int, optional) – Number of walkers, by default 32

  • steps (int, optional) – Number of steps, by default 1600

  • progress (bool, optional) – Print progress bar, by default True

calc_mc_errors(percentiles=[15.87, 50, 84.13], discard=None, thin=None)

Computes percentiles from Monte Carlo samples.

Parameters
  • percentiles (list, optional) – Percentiles for each parameter, by default [15.87,50,84.13]

  • discard (int, optional) – Number of “burn-in” steps to discard, by default 100

  • thin (int, optional) – N, by default 10

Returns

errors – Errors from Monte Carlo sampling.

Return type

array

corner_plot(quantiles=[0.16, 0.84], labels=None, **kwargs)

Utility function for generating corner plots.

Parameters
  • quantiles (list, optional) – Quantiles to annotate, by default (0.16,0.84)

  • labels (list, optional) – Parameter labels, by default None

Returns

  • fig (Figure) – Figure object.

  • axes (Axes) – Axes object.

sample_plot(fig=None, labels=[], fig_kwgs={}, ax_kwgs={})

Plot the accepted Monte Carlo samples.

Parameters
  • fig (object, optional) – Figure object, by default None

  • labels (list, optional) – Plot labels, by default []

  • fig_kwgs (dict, optional) – Figure keywords, by default {}

  • ax_kwgs (dict, optional) – Axes keywords, by default {}

Returns

  • fig (Figure) – Figure object.

  • axes (Axes) – Axes object.

class tweezepy.MLE.MLEfit(pedantic=True, scale_covar=False, minimizer_kwargs={})

Perform maximum likelihood estimation and uncertainty calculations.

Parameters
  • pedantic (bool, optional) – Ignore unhelpful warnings, by default True

  • scale_covar (bool, optional) – Whether to scale standard errors by reduced chi-squared, by default False

  • fit_kwargs (dict, optional) – Disctionary of keyword arguments passed to scipy.optimize.minimize, by default {}.

names

Fit function parameter names.

Type

list

params

Parameter values.

Type

array

std_errors

Parameter uncertainties.

Type

array

chi2

Chi-squared value.

Type

float

redchi2

Reduced chi-squared value.

Type

float

AIC

Akaike information criterion.

Type

float

AICc

Corrected Akaike information criterion.

Type

float

mcmc(walkers=32, steps=2000, discard=100, thin=10)

Runs Monte Carlo sampler and computes standard errors as 0.5*(std_u - std_l)

Parameters
  • walkers (int, optional) – Number of walkers, by default 32

  • steps (int, optional) – Number of steps to take, by default 2000

  • discard (int, optional) – Number of initial steps to discard, by default 100

  • thin (int, optional) – Distance between independent steps, by default 10

property results

Dictionary of MLE fit results.

Returns

Dictionary of MLE fit results.

Return type

dict

class tweezepy.MLE.Gamma_Distribution(shape, yhat)

Gamma probability distribution class.

Parameters
  • shape (np.array) – Shape parameter.

  • yhat (np.array) – Experimental values.

shape

Shape parameters.

Type

array-like

yhat

Experimnetal values

Type

array-like

cdf(ytrue)

Cumulative distribution function.

Parameters

ytrue (array-like) – True/theoretical values.

Returns

cdf – Cumulative distribution function.

Return type

callable

interval(ytrue, alpha=0.95)
Parameters
  • ytrue (array-like) – True/theoretical values.

  • alpha (float, optional) – Probability that a random variable will be drawn from the returned range. Each value should be in the range [0, 1]., by default 0.95

Returns

Interval – Endpoints of the range that contains fraction alpha [0, 1] of the distribution.

Return type

callable

logcdf(ytrue)

Log of cumulative distribution function.

Parameters

ytrue (array-like) – True/theoretical values.

Returns

logcdf – Log of cumulative distribution function.

Return type

callable

logpdf(ytrue)

Log of the probability distribution function.

Parameters

ytrue (array-like) – True/theoretical values.

Returns

logpdf – Log of the probability distribution function.

Return type

callable

pdf(ytrue)

Calculate probability distribution function.

Parameters

ytrue (array-like) – True/theoretical values.

Returns

pdf – Probability distribution function.

Return type

callable

scale(ytrue)

Calculate scale parameters.

Parameters

ytrue (array-like) – True/theoretical values.

Returns

scale – Scale parameters.

Return type

array-like

std(ytrue)

Calculate standard deviation.

Parameters

ytrue (array-like) – True/theoretical values.

Returns

std – Standard deviations.

Return type

array-like