getdist.gaussian_mixtures

class getdist.gaussian_mixtures.Gaussian1D(mean, sigma, **kwargs)[source]

Simple 1D Gaussian

Parameters
  • mean – mean

  • sigma – standard deviation

  • kwargs – arguments passed to Mixture1D

class getdist.gaussian_mixtures.Gaussian2D(mean, cov, **kwargs)[source]

Simple special case of a 2D Gaussian mixture model with only one Gaussian component

Parameters
  • mean – 2 element array with mean

  • cov – 2x2 array of covariance, or list of [sigma_x, sigma_y, correlation] values

  • kwargs – arguments passed to Mixture2D

class getdist.gaussian_mixtures.GaussianND(mean, cov, is_inv_cov=False, **kwargs)[source]

Simple special case of a Gaussian mixture model with only one Gaussian component

Parameters
  • mean – array specifying y of parameters

  • cov – covariance matrix (or filename of text file with covariance matrix)

  • is_inv_cov – set True if cov is actually an inverse covariance

  • kwargs – arguments passed to MixtureND

class getdist.gaussian_mixtures.Mixture1D(means, sigmas, weights=None, lims=None, name='x', xmin=None, xmax=None, **kwargs)[source]

Gaussian mixture model in 1D with optional boundaries for fixed ranges

Parameters
  • means – array of y for each component

  • sigmas – array of standard deviations for each component

  • weights – weights for each component (defaults to equal weight)

  • lims – optional array limits for each component

  • name – parameter name (default ‘x’)

  • xmin – optional lower limit

  • xmax – optional upper limit

  • kwargs – arguments passed to MixtureND

pdf(x)[source]

Calculate the PDF. Note this assumes x is within the boundaries (does not return zero outside) Result is also only normalized if no boundaries.

Parameters

x – array of parameter values to evaluate at

Returns

pdf at x

class getdist.gaussian_mixtures.Mixture2D(means, covs, weights=None, lims=None, names=('x', 'y'), xmin=None, xmax=None, ymin=None, ymax=None, **kwargs)[source]

Gaussian mixture model in 2D with optional boundaries for fixed x and y ranges

Parameters
  • means – list of y for each Gaussian in the mixture

  • covs – list of covariances for the Gaussians in the mixture. Instead of 2x2 arrays, each cov can also be a list of [sigma_x, sigma_y, correlation] parameters

  • weights – optional weight for each component (defaults to equal weight)

  • lims – optional list of hard limits for each parameter, [[x1min,x1max], [x2min,x2max]]; use None for no limit

  • names – list of names (strings) for each parameter. If not set, set to x, y

  • xmin – optional lower hard bound for x

  • xmax – optional upper hard bound for x

  • ymin – optional lower hard bound for y

  • ymax – optional upper hard bound for y

  • kwargs – arguments passed to MixtureND

pdf(x, y=None)[source]

Calculate the PDF. Note this assumes x and y are within the boundaries (does not return zero outside) Result is also only normalized if no boundaries

Parameters
  • x – value of x to evaluate pdf

  • y – optional value of y to evaluate pdf. If not specified, returns 1D marginalized value for x.

Returns

value of pdf at x or x,y

class getdist.gaussian_mixtures.MixtureND(means, covs, weights=None, lims=None, names=None, label='', labels=None)[source]

Gaussian mixture model with optional boundary ranges. Includes functions for generating samples and projecting.

Parameters
  • means – list of y for each Gaussian in the mixture

  • covs – list of covariances for the Gaussians in the mixture

  • weights – optional weight for each component (defaults to equal weight)

  • lims – optional list of hard limits for each parameter, [[x1min,x1max], [x2min,x2max]]; use None for no limit

  • names – list of names (strings) for each parameter. If not set, set to “param1”, “param2”…

  • label – name for labelling this mixture

  • labels – list of latex labels for each parameter. If not set, defaults to p_{1}, p_{2}…

MCSamples(size, names=None, logLikes=False, random_state=None, **kwargs)[source]

Gets a set of independent samples from the mixture as a mcsamples.MCSamples object ready for plotting etc.

Parameters
  • size – number of samples

  • names – set to override existing names

  • logLikes – if True set the sample likelihood values from the pdf, if false, don’t store log likelihoods

  • random_state – random seed or Generator

Returns

a new mcsamples.MCSamples instance

conditionalMixture(fixed_params, fixed_param_values, label=None)[source]

Returns a reduced conditional mixture model for the distribution when certainly parameters are fixed.

Parameters
  • fixed_params – list of names or numbers of parameters to fix

  • fixed_param_values – list of values for the fixed parameters

  • label – optional label for the new mixture

Returns

A new MixtureND instance with cov_i = Projection(Cov_i^{-1})^{-1} and shifted conditional y

density1D(index=0, num_points=1024, sigma_max=4, no_limit_marge=False)[source]

Get 1D marginalized density. Only works if no hard limits in other parameters.

Parameters
  • index – parameter name or index

  • num_points – number of grid points to evaluate PDF

  • sigma_max – maximum number of standard deviations away from y to include in computed range

  • no_limit_marge – if true don’t raise error if limits on other parameters

Returns

Density1D instance

density2D(params=None, num_points=1024, xmin=None, xmax=None, ymin=None, ymax=None, sigma_max=5)[source]

Get 2D marginalized density for a pair of parameters.

Parameters
  • params – list of two parameter names or indices to use. If already 2D, can be None.

  • num_points – number of grid points for evaluation

  • xmin – optional lower value for first parameter

  • xmax – optional upper value for first parameter

  • ymin – optional lower value for second parameter

  • ymax – optional upper value for second parameter

  • sigma_max – maximum number of standard deviations away from mean to include in calculated range

Returns

Density2D instance

marginalizedMixture(params, label=None, no_limit_marge=False) getdist.gaussian_mixtures.MixtureND[source]

Calculates a reduced mixture model by marginalization over unwanted parameters

Parameters
  • params – array of parameter names or indices to retain. If none, will simply return a copy of this mixture.

  • label – optional label for the marginalized mixture

  • no_limit_marge – if true don’t raise an error if mixture has limits.

Returns

a new marginalized MixtureND instance

pdf(x)[source]

Calculate the PDF. Note this assumes x is within the boundaries (does not return zero outside) Result is also only normalized if no boundaries.

Parameters

x – array of parameter values to evaluate at

Returns

pdf at x

pdf_marged(index, x, no_limit_marge=False)[source]

Calculate the 1D marginalized PDF. Only works if no other parameter limits are marginalized

Parameters
  • index – index or name of parameter

  • x – value to evaluate PDF at

  • no_limit_marge – if true don’t raise an error if mixture has limits

Returns

marginalized 1D pdf at x

sim(size, random_state=None)[source]

Generate an array of independent samples

Parameters
  • size – number of samples

  • random_state – random number Generator or seed

Returns

2D array of sample values

class getdist.gaussian_mixtures.RandomTestMixtureND(ndim=4, ncomponent=1, names=None, weights=None, seed=None, label='RandomMixture')[source]

class for randomly generating an N-D gaussian mixture for testing (a mixture with random parameters, not random samples from the mixture).

Parameters
  • ndim – number of dimensions

  • ncomponent – number of components

  • names – names for the parameters

  • weights – weights for each component

  • seed – random seed or Generator

  • label – label for the generated mixture

getdist.gaussian_mixtures.randomTestMCSamples(ndim=4, ncomponent=1, nsamp=10009, nMCSamples=1, seed=10, names=None, labels=None)[source]

get a MCSamples instance, or list of MCSamples instances with random samples from random covariances and y