getdist.mcsamples

getdist.mcsamples.loadMCSamples(file_root, ini=None, jobItem=None, no_cache=False, settings={}, dist_settings={})[source]

Loads a set of samples from a file or files.

Sample files are plain text (file_root.txt) or a set of files (file_root_1.txt, file_root_2.txt, etc.).

Auxiliary files file_root.paramnames gives the parameter names and (optionally) file_root.ranges gives hard prior parameter ranges.

For a description of the various analysis settings and default values see analysis_defaults.ini.

Parameters:
  • file_root – The root name of the files to read (no extension)
  • ini – The name of a .ini file with analysis settings to use
  • jobItem – an optional grid jobItem instance for a CosmoMC grid output
  • no_cache – Indicates whether or not we should cached loaded samples in a pickle
  • settings – dictionary of analysis settings to override defaults
  • dist_settings – (old) alias for settings
Returns:

The MCSamples instance

class getdist.mcsamples.MCSamples(root=None, jobItem=None, ini=None, settings=None, ranges=None, **kwargs)[source]

The main high-level class for a collection of parameter samples.

Derives from chains.Chains, adding high-level functions including Kernel Density estimates, parameter ranges and custom settings.

For a description of the various analysis settings and default values see analysis_defaults.ini.

Parameters:
  • root – A root file name when loading from file
  • jobItem – Optional paramgrid.batchjob.jobItem instance if a member of a parameter grid
  • ini – a .ini file to use for custom analysis settings
  • settings – a dictionary of custom analysis settings
  • ranges – a dictionary giving any additional hard prior bounds for parameters, eg. {‘x’:[0, 1], ‘y’:[None,2]}
  • kwargs

    keyword arguments passed to inherited classes, e.g. to manually make a samples object from sample arrays in memory:

    • paramNamesFile: optional name of .paramnames file with parameter names
    • samples: array of parameter values for each sample, passed to setSamples()
    • weights: array of weights for samples
    • loglikes: array of -log(Likelihood) for samples
    • names: list of names for the parameters
    • labels: list of latex labels for the parameters
    • ignore_rows:
      • if int >=1: The number of rows to skip at the file in the beginning of the file
      • if float <1: The fraction of rows to skip at the beginning of the file
    • name_tag: a name tag for this instance
PCA(params, param_map=None, normparam=None, writeDataToFile=False, filename=None, conditional_params=[])[source]

Perform principle component analysis (PCA). In other words, get eigenvectors and eigenvalues for normalized variables with optional (log modulus) mapping to find power law fits.

Parameters:
  • params – List of names of the parameters to use
  • param_map – A transformation to apply to parameter values; A list or string containing either N (no transformation) or L (for log transform) for each parameter. By default uses log if no parameter values cross zero
  • normparam – optional name of parameter to normalize result (i.e. this parameter will have unit power)
  • writeDataToFile – True if should write the output to file.
  • filename – The filename to write, by default root_name.PCA.
  • conditional_params – optional list of parameters to treat as fixed, i.e. for PCA conditional on fixed values of these parameters
Returns:

a string description of the output of the PCA

addDerived(paramVec, name, **kwargs)

Adds a new parameter

Parameters:
  • paramVec – The vector of parameter values to add.
  • name – The name for the new parameter
  • kwargs – arguments for paramnames’ addDerived()
Returns:

The added parameter’s ParamInfo object

changeSamples(samples)

Sets the samples without changing weights and loglikes.

Parameters:samples – The samples to set
confidence(paramVec, limfrac, upper=False, start=0, end=None, weights=None)

Calculate sample confidence limits, not using kernel densities just counting samples in the tails

Parameters:
  • paramVec – array of parameter values or int index of parameter to use
  • limfrac – fraction of samples in the tail, e.g. 0.05 for a 95% one-tail limit, or 0.025 for a 95% two-tail limit
  • upper – True to get upper limit, False for lower limit
  • start – Start index for the vector to use
  • end – The end index, use None to go all the way to the end of the vector.
  • weights – numpy array of weights for each sample, by default self.weights
Returns:

confidence limit (parameter value when limfac of samples are further in the tail)

cool(cool)

Cools the samples, i.e. multiples log likelihoods by cool factor and re-weights accordingly

Parameters:cool – cool factor
corr(pars=None)

Get the correlation matrix

Parameters:pars – If specified, list of parameter vectors or int indices to use
Returns:The correlation matrix.
cov(pars=None, where=None)

Get parameter covariance

Parameters:
  • pars – if specified, a list of parameter vectors or int indices to use
  • where – if specified, a filter for the samples to use (where x>=5 would mean only process samples with x>=5).
Returns:

The covariance matrix

deleteFixedParams()

Delete parameters that are fixed (the same value in all samples)

deleteZeros()

Removes samples with zero weight

filter(where)

Filter the stored samples to keep only samples matching filter

Parameters:where – list of sample indices to keep, or boolean array filter (e.g. x>5 to keep only samples where x>5)
get1DDensity(name, **kwargs)[source]

Returns a Density1D instance for parameter with given name. Result is cached.

Parameters:
Returns:

A Density1D instance for parameter with given name

get1DDensityGridData(j, writeDataToFile=False, get_density=False, paramConfid=None, meanlikes=False, **kwargs)[source]

Low-level function to get a Density1D instance for the marginalized 1D density of a parameter. Result is not cached.

Parameters:
  • j – a name or index of the parameter
  • writeDataToFile – True if should write to text file.
  • get_density – return a Density1D instance only, does not write out or calculate mean likelihoods for plots
  • paramConfid – optional cached ParamConfidenceData instance
  • meanlikes – include mean likelihoods
  • kwargs

    optional settings to override instance settings of the same name (see analysis_settings):

    • smooth_scale_1D
    • boundary_correction_order
    • mult_bias_correction_order
    • fine_bins
    • num_bins
Returns:

A Density1D instance

get2DDensity(x, y, normalized=False, **kwargs)[source]

Returns a Density2D instance with marginalized 2D density.

Parameters:
  • x – index or name of x parameter
  • y – index or name of y parameter
  • kwargs – keyword arguments for the get2DDensityGridData() function
  • normalized – if False, is normalized so the maximum is 1, if True, density is normalized
Returns:

Density2D instance

get2DDensityGridData(j, j2, writeDataToFile=False, num_plot_contours=None, get_density=False, meanlikes=False, **kwargs)[source]

Low-level function to get 2D plot marginalized density and optional additional plot data.

Parameters:
  • j – name or index of the x parameter
  • j2 – name or index of the y parameter.
  • writeDataToFile – True if should write data to file
  • num_plot_contours – number of contours to calculate and return in density.contours
  • get_density – only get the 2D marginalized density, no additional plot data
  • meanlikes – calculate mean likelihoods as well as marginalized density (returned as array in density.likes)
  • kwargs

    optional settings to override instance settings of the same name (see analysis_settings):

    • fine_bins_2D
    • boundary_correction_order
    • mult_bias_correction_order
    • smooth_scale_2D
Returns:

a Density2D instance

getAutoBandwidth1D(bins, par, param, mult_bias_correction_order=None, kernel_order=1, N_eff=None)[source]

Get optimized kernel density bandwidth (in units of the range of the bins) Based on optimal Improved Sheather-Jones bandwidth for basic Parzen kernel, then scaled if higher-order method being used. For details see the notes.

Parameters:
  • bins – numpy array of binned weights for the samples
  • par – A ParamInfo instance for the parameter to analyse
  • param – index of the parameter to use
  • mult_bias_correction_order – order of multiplicative bias correction (0 is basic Parzen kernel); by default taken from instance settings.
  • kernel_order – order of the kernel (0 is Parzen, 1 does linear boundary correction, 2 is a higher-order kernel)
  • N_eff – effective number of samples. If not specified estimated using weights, autocorrelations, and fiducial bandwidth
Returns:

kernel density bandwidth (in units the range of the bins)

getAutoBandwidth2D(bins, parx, pary, paramx, paramy, corr, rangex, rangey, base_fine_bins_2D, mult_bias_correction_order=None, min_corr=0.2, N_eff=None)[source]

Get optimized kernel density bandwidth matrix in parameter units, using Improved Sheather Jones method in sheared parameters. For details see the notes.

Parameters:
  • bins – 2D numpy array of binned weights
  • parx – A ParamInfo instance for the x parameter
  • pary – A ParamInfo instance for the y parameter
  • paramx – index of the x parameter
  • paramy – index of the y parameter
  • corr – correlation of the samples
  • rangex – scale in the x parameter
  • rangey – scale in the y parameter
  • base_fine_bins_2D – number of bins to use for re-binning in rotated parameter space
  • mult_bias_correction_order – multiplicative bias correction order (0 is Parzen kernel); by default taken from instance settings
  • min_corr – minimum correlation value at which to bother de-correlating the parameters
  • N_eff – effective number of samples. If not specified, currently uses crude estimate from effective numbers in x and y separately
Returns:

kernel density bandwidth matrix in parameter units

getAutocorrelation(paramVec, maxOff=None, weight_units=True, normalized=True)

Gets auto-correlation of an array of parameter values (e.g. for correlated samples from MCMC)

By default uses weight units (i.e. standard units for separate samples from original chain). If samples are made from multiple chains, neglects edge effects.

Parameters:
  • paramVec – an array of parameter values, or the int index of the parameter in stored samples to use
  • maxOff – maximum autocorrelation distance to return
  • weight_units – False to get result in sample point (row) units; weight_units=False gives standard definition for raw chains
  • normalized – Set to False to get covariance (note even if normalized, corr[0]<>1 in general unless weights are unity).
Returns:

zero-based array giving auto-correlations

getBounds()[source]

Returns the bounds in the form of a ParamBounds instance, for example for determining plot ranges

Bounds are not the same as self.ranges, as if samples are not near the range boundary, the bound is set to None

Returns:a ParamBounds instance
getConvergeTests(test_confidence=0.95, writeDataToFile=False, what=['MeanVar', 'GelmanRubin', 'SplitTest', 'RafteryLewis', 'CorrLengths'], filename=None, feedback=False)[source]

Do convergence tests.

Parameters:
  • test_confidence – confidence limit to test for convergence (two-tail, only applies to some tests)
  • writeDataToFile – True if should write output to a file
  • what

    The tests to run. Should be a list of any of the following:

    • ‘MeanVar’: Gelman-Rubin sqrt(var(chain mean)/mean(chain var)) test in individual parameters (multiple chains only)
    • ‘GelmanRubin’: Gelman-Rubin test for the worst orthogonalized parameter (multiple chains only)
    • ‘SplitTest’: Crude test for variation in confidence limits when samples are split up into subsets
    • ‘RafteryLewis’: Raftery-Lewis test (integer weight samples only)
    • ‘CorrLengths’: Sample correlation lengths
  • filename – The filename to write to, default is file_root.converge
  • feedback – If set to True, Prints the output as well as returning it.
Returns:

text giving the output of the tests

getCorrelatedVariable2DPlots(num_plots=12, nparam=None)[source]

Gets a list of most correlated variable pair names.

Parameters:
  • num_plots – The number of plots
  • nparam – maximum number of pairs to get
Returns:

list of [x,y] pair names

getCorrelationLength(j, weight_units=True, min_corr=0.05, corr=None)

Gets the auto-correlation length for parameter j

Parameters:
  • j – The index of the parameter to use
  • weight_units – False to get result in sample point (row) units; weight_units=False gives standard definition for raw chains
  • min_corr – specifies a minimum value of the autocorrelation to use, e.g. where sampling noise is typically as large as the calculation
  • corr – The auto-correlation array to use, calculated internally by default using getAutocorrelation()
Returns:

the auto-correlation length

getCorrelationMatrix()

Get the correlation matrix of all parameters

Returns:The correlation matrix
getCov(nparam=None, pars=None)

Get covariance matrix of the parameters. By default uses all parameters, or can limit to max number or list.

Parameters:
  • nparam – if specified, only use the first nparam parameters
  • pars – if specified, a list of parameter indices (0,1,2..) to include
Returns:

covariance matrix.

getCovMat()[source]

Gets the CovMat instance containing covariance matrix for all the non-derived parameters (for example useful for subsequent MCMC runs to orthogonalize the parameters)

Returns:A CovMat object holding the covariance
getEffectiveSamples(j=0, min_corr=0.05)

Gets effective number of samples N_eff so that the error on mean of parameter j is sigma_j/N_eff

Parameters:
  • j – The index of the param to use.
  • min_corr – the minimum value of the auto-correlation to use when estimating the correlation length
getEffectiveSamplesGaussianKDE(paramVec, h=0.2, scale=None, maxoff=None, min_corr=0.05)

Roughly estimate an effective sample number for use in the leading term for the MISE (mean integrated squared error) of a Gaussian-kernel KDE (Kernel Density Estimate). This is used for optimizing the kernel bandwidth, and though approximate should be better than entirely ignoring samples correlations, or only counting distinct samples.

Uses fiducial assumed kernel scale h; result does depend on this (typically by factors O(2))

For bias-corrected KDE only need very rough estimate to use in rule of thumb for bandwidth.

In the limit h-> 0 (but still >0) answer should be correct (then just includes MCMC rejection duplicates). In reality correct result for practical h should depends on shape of the correlation function

Parameters:
  • paramVec – parameter array, or int index of parameter to use
  • h – fiducial assumed kernel scale.
  • scale – a scale parameter to determine fiducial kernel width, by default the parameter standard deviation
  • maxoff – maximum value of auto-correlation length to use
  • min_corr – ignore correlations smaller than this auto-correlation
Returns:

A very rough effective sample number for leading term for the MISE of a Gaussian KDE.

getFractionIndices(weights, n)[source]

Calculates the indices of weights that split the weights into sets of equal 1/n fraction of the total weight

Parameters:
  • weights – array of weights
  • n – number of groups to split in to
Returns:

array of indices of the boundary rows in the weights array

getGelmanRubin(nparam=None, chainlist=None)

Assess the convergence using the maximum var(mean)/mean(var) of orthogonalized parameters c.f. Brooks and Gelman 1997.

Parameters:
  • nparam – The number of parameters, by default uses all
  • chainlist – list of WeightedSamples, the samples to use. Defaults to all the separate chains in this instance.
Returns:

The worst var(mean)/mean(var) for orthogonalized parameters. Should be <<1 for good convergence.

getGelmanRubinEigenvalues(nparam=None, chainlist=None)

Assess convergence using var(mean)/mean(var) in the orthogonalized parameters c.f. Brooks and Gelman 1997.

Parameters:
  • nparam – The number of parameters (starting at first), by default uses all of them
  • chainlist – list of WeightedSamples, the samples to use. Defaults to all the separate chains in this instance.
Returns:

array of var(mean)/mean(var) for orthogonalized parameters

getInlineLatex(param, limit=1)[source]

Get snippet like: A=x\pm y. Will adjust appropriately for one and two tail limits.

Parameters:
  • param – The name of the parameter
  • limit – which limit to get, 1 is the first (default 68%), 2 is the second (limits array specified by self.contours)
Returns:

The tex snippet.

getLabel()

Return the latex label for the samples

Returns:the label
getLatex(params=None, limit=1)[source]

Get tex snippet for constraints on a list of parameters

Parameters:
  • params – list of parameter names
  • limit – which limit to get, 1 is the first (default 68%), 2 is the second (limits array specified by self.contours)
Returns:

labels, texs: a list of parameter labels, and a list of tex snippets

getLikeStats()[source]

Get best fit sample and n-D confidence limits, and various likelihood based statistics

Returns:a LikeStats instance storing N-D limits for parameter i in result.names[i].ND_limit_top, result.names[i].ND_limit_bot, and best-fit sample value in result.names[i].bestfit_sample
getLower(name)[source]

Return the lower limit of the parameter with the given name.

Parameters:name – parameter name
Returns:The lower limit if name exists, None otherwise.
getMargeStats(include_bestfit=False)[source]

Returns a MargeStats object with marginalized 1D parameter constraints

Parameters:include_bestfit – if True, set best fit values by loading from root_name.minimum file (assuming it exists)
Returns:A MargeStats instance
getMeans()

Gets the parameter means, from saved array if previously calculated.

Returns:numpy array of parameter means
getName()

Returns the name tag of these samples.

Returns:The name tag
getNumSampleSummaryText()[source]

Returns a summary text describing numbers of parameters and samples, and various measures of the effective numbers of samples.

Returns:The summary text as a string.
getParamNames()

Get ParamNames object with names for the parameters

Returns:ParamNames object giving parameter names and labels
getParamSampleDict(ix)[source]

Returns a dictionary of parameter values for sample number ix

getParams()

Creates a ParSamples object, with variables giving vectors for all the parameters, for example samples.getParams().name1 would be the vector of samples with name ‘name1’

Returns:A ParSamples object containing all the parameter vectors, with attributes given by the parameter names
getRawNDDensity(xs, normalized=False, **kwargs)[source]

Returns a DensityND instance with marginalized ND density.

Parameters:
  • xs – indices or names of x_i parameters
  • kwargs – keyword arguments for the getNDDensityGridData() function
  • normalized – if False, is normalized so the maximum is 1, if True, density is normalized
Returns:

DensityND instance

getRawNDDensityGridData(js, writeDataToFile=False, num_plot_contours=None, get_density=False, meanlikes=False, maxlikes=False, **kwargs)[source]

Low-level function to get unsmooth ND plot marginalized density and optional additional plot data.

Parameters:
  • js – vector of names or indices of the x_i parameters
  • writeDataToFile – True if should write data to file
  • num_plot_contours – number of contours to calculate and return in density.contours
  • get_density – only get the ND marginalized density, no additional plot data, no contours.
  • meanlikes – calculate mean likelihoods as well as marginalized density (returned as array in density.likes)
  • maxlikes – calculate the profile likelihoods in addition to the others (returned as array in density.maxlikes)
  • kwargs – optional settings to override instance settings of the same name (see analysis_settings):
Returns:

a DensityND instance

getSeparateChains()

Gets a list of samples for separate chains. If the chains have already been combined, uses the stored sample offsets to reconstruct the array (generally no array copying)

Returns:The list of WeightedSamples for each chain.
getSignalToNoise(params, noise=None, R=None, eigs_only=False)

Returns w, M, where w is the eigenvalues of the signal to noise (small means better constrained)

Parameters:
  • params – list of parameters indices to use
  • noise – noise matrix
  • R – rotation matrix, defaults to inverse of Cholesky root of the noise matrix
  • eigs_only – only return eigenvalues
Returns:

w, M, where w is the eigenvalues of the signal to noise (small means better constrained)

getTable(columns=1, include_bestfit=False, **kwargs)[source]

Creates and returns a ResultTable instance.

Parameters:
  • columns – number of columns in the table
  • include_bestfit – True if should include the bestfit parameter values (assuming set)
  • kwargs – arguments for ResultTable constructor.
Returns:

A ResultTable instance

getUpper(name)[source]

Return the upper limit of the parameter with the given name.

Parameters:name – parameter name
Returns:The upper limit if name exists, None otherwise.
getVars()

Get the parameter variances

Returns:A numpy array of variances.
get_norm(where=None)

gets the normalization, the sum of the sample weights: sum_i w_i

Parameters:where – if specified, a filter for the samples to use (where x>=5 would mean only process samples with x>=5).
Returns:normalization
initParamConfidenceData(paramVec, start=0, end=None, weights=None)

Initialize cache of data for calculating confidence intervals

Parameters:
  • paramVec – array of parameter values or int index of parameter to use
  • start – The sample start index to use
  • end – The sample end index to use, use None to go all the way to the end of the vector
  • weights – A numpy array of weights for each sample, defaults to self.weights
Returns:

ParamConfidenceData instance

initParameters(ini)[source]

Initializes settings. Gets parameters from IniFile.

Parameters:ini – The IniFile to be used
loadChains(root, files, ignore_lines=None)

Loads chains from files.

Parameters:
  • root – Root name
  • files – list of file names
  • ignore_lines – Amount of lines at the start of the file to ignore, None if should not ignore
Returns:

True if loaded successfully, False if none loaded

makeSingle()

Combines separate chains into one samples array, so self.samples has all the samples and this instance can then be used as a general WeightedSamples instance.

Returns:self
makeSingleSamples(filename='', single_thin=None)[source]

Make file of weight-1 samples by choosing samples with probability given by their weight.

Parameters:
  • filename – The filename to write to, Leave empty if no output file is needed
  • single_thin – factor to thin by; if not set generates as many samples as it can
Returns:

numpy array of selected weight-1 samples

mean(paramVec, where=None)

Get the mean of the given parameter vector.

Parameters:
  • paramVec – array of parameter values or int index of parameter to use
  • where – if specified, a filter for the samples to use (where x>=5 would mean only process samples with x>=5).
Returns:

parameter mean

mean_diff(paramVec, where=None)

Calculates an array of differences between a parameter vector and the mean parameter value

Parameters:
  • paramVec – array of parameter values or int index of parameter to use
  • where – if specified, a filter for the samples to use (where x>=5 would mean only process samples with x>=5).
Returns:

array of p_i - mean(p_i)

mean_diffs(pars=None, where=None)

Calculates a list of parameter vectors giving distances from parameter means

Parameters:
  • pars – if specified, list of parameter vectors or int parameter indices to use
  • where – if specified, a filter for the samples to use (where x>=5 would mean only process samples with x>=5).
Returns:

list of arrays p_i-mean(p-i) for each parameter

parLabel(i)[source]

Gets the latex label of the parameter

Parameters:i – The index or name of a parameter.
Returns:The parameter’s label.
parName(i, starDerived=False)[source]

Gets the name of i’th parameter

Parameters:
  • i – The index of the parameter
  • starDerived – add a star at the end of the name if the parameter is derived
Returns:

The name of the parameter (string)

randomSingleSamples_indices()

Returns an array of sample indices that give a list of weight-one samples, by randomly selecting samples depending on the sample weights

Returns:array of sample indices
readChains(chain_files)[source]

Loads samples from a list of files, removing burn in, deleting fixed parameters, and combining into one self.samples array

Parameters:chain_files – The list of file names to read
Returns:self.
removeBurn(remove=0.3)

removes burn in from the start of the samples

Parameters:remove – fraction of samples to remove, or if int >1, the number of sample rows to remove
removeBurnFraction(ignore_frac)

Remove a fraction of the samples as burn in

Parameters:ignore_frac – fraction of sample points to remove from the start of the samples, or each chain if not combined
reweightAddingLogLikes(logLikes)

Importance sample the samples, by adding logLike (array of -log(likelihood values) to the currently stored likelihoods, and re-weighting accordingly, e.g. for adding a new data constraint

Parameters:logLikes – array of -log(likelihood) for each sample to adjust
saveAsText(root, chain_index=None, make_dirs=False)[source]

Saves samples as text file, including .ranges and .paramnames.

Parameters:
  • root – The root file name to use.
  • chain_index – optional index to be used for the filename.
  • make_dirs – True if should create the directories
savePickle(filename)

Save the current object to a file in pickle format

Parameters:filename – The file to write to
setColData(coldata, are_chains=True)

Set the samples given an array loaded from file

Parameters:
  • coldata – The array with columns of [weights, -log(Likelihoods)] and sample parameter values
  • are_chains – True if coldata starts with two columns giving weight and -log(Likelihood)
setDiffs()

saves self.diffs array of parameter differences from the means, e.g. to later calculate variances etc.

Returns:array of differences
setMeans()

Calculates and saves the means for the samples

Returns:numpy array of parameter means
setParamNames(names=None)

Sets the names of the params.

Parameters:names – Either a ParamNames object, the name of a .paramnames file to load, a list of name strings, otherwise use default names (param1, param2...).
setParams(obj)

Adds array variables obj.name1, obj.name2 etc, where obj.name1 is the vector of samples with name ‘name1’

if a parameter name is of the form aa.bb.cc, it makes subobjects so you can reference obj.aa.bb.cc

Parameters:obj – The object instance to add the parameter vectors variables
Returns:The obj after alterations.
setRanges(ranges)[source]

Sets the ranges parameters, e.g. hard priors on positivity etc. If a min or max value is None, then it is assumed to be unbounded.

Parameters:ranges – A list or a tuple of [min,max] values for each parameter, or a dictionary giving [min,max] values for specific parameter names
setSamples(samples, weights=None, loglikes=None)

Sets the samples from numpy arrays

Parameters:
  • samples – The samples values, n_samples x n_parameters numpy array, or can be a list of parameter vectors
  • weights – Array of weights for each sample. Defaults to 1 for all samples if unspecified.
  • loglikes – Array of -log(Likelihood) values for each sample
std(paramVec, where=None)

Get the standard deviation of the given parameter vector.

Parameters:
  • paramVec – array of parameter values or int index of parameter to use
  • where – if specified, a filter for the samples to use (where x>=5 would mean only process samples with x>=5).
Returns:

parameter standard deviation.

thin(factor)

Thin the samples by the given factor, giving set of samples with unit weight

Parameters:factor – The factor to thin by
thin_indices(factor, weights=None)

Indices to make single weight 1 samples. Assumes integer weights.

Parameters:
  • factor – The factor to thin by, should be int.
  • weights – The weights to thin, None if this should use the weights stored in the object.
Returns:

array of indices of samples to keep

twoTailLimits(paramVec, confidence)

Calculates two-tail equal-area confidence limit by counting samples in the tails

Parameters:
  • paramVec – array of parameter values or int index of parameter to use
  • confidence – confidence limit to calculate, e.g. 0.95 for 95% confidence
Returns:

min, max values for the confidence interval

updateBaseStatistics()[source]

Updates basic computed statistics (means, covariance etc), e.g. after a change in samples or weights

Returns:self
updateSettings(settings=None, ini=None, doUpdate=True)[source]

Updates settings from a .ini file or dictionary

Parameters:
  • settings – The a dict containing settings to set, taking preference over any values in ini
  • ini – The name of .ini file to get settings from, or an IniFile instance; by default uses current settings
  • doUpdate – True if should update internal computed values, False otherwise (e.g. if want to make other changes first)
var(paramVec, where=None)

Get the variance of the given parameter vector.

Parameters:
  • paramVec – array of parameter values or int index of parameter to use
  • where – if specified, a filter for the samples to use (where x>=5 would mean only process samples with x>=5).
Returns:

parameter variance

weighted_sum(paramVec, where=None)

Calculates the weighted sum of a parameter vector, sum_i w_i p_i

Parameters:
  • paramVec – array of parameter values or int index of parameter to use
  • where – if specified, a filter for the samples to use (where x>=5 would mean only process samples with x>=5).
Returns:

weighted sum

writeCorrelationMatrix(filename=None)[source]

Write the correlation matrix to a file

Parameters:filename – The file to write to, If none writes to file_root.corr
writeCovMatrix(filename=None)[source]

Writes the covrariance matrix of non-derived parameters to a file.

Parameters:filename – The filename to write to; default is file_root.covmat
writeScriptPlots1D(filename, plotparams=None, ext=None)[source]

Write a script that generates a 1D plot. Only intended for use by GetDist.py script.

Parameters:
  • filename – The filename to write to.
  • plotparams – The list of parameters to plot (default: all)
  • ext – The extension for the filename, Default if None
writeScriptPlots2D(filename, plot_2D_param=None, cust2DPlots=[], writeDataToFile=False, ext=None, shade_meanlikes=False)[source]

Write script that generates a 2 dimensional plot. Only intended for use by GetDist.py script.

Parameters:
  • filename – The filename to write to.
  • plot_2D_param – parameter to plot other variables against
  • cust2DPlots – list of parts of parameter names to plot
  • writeDataToFile – True if should write to file
  • ext – The extension for the filename, Default if None
  • shade_meanlikes – shade by mean likelihoods
Returns:

A dictionary indexed by pairs of parameters where 2D densities have been calculated

writeScriptPlots3D(filename, plot_3D, ext=None)[source]

Writes a script that generates a 3D (coloured-scatter) plot. Only intended for use by GetDist.py script.

Parameters:
  • filename – The filename to write to
  • plot_3D – list of [x,y,z] parameters for the 3 Dimensional plots
  • ext – The extension for the filename, Default if None
writeScriptPlotsTri(filename, triangle_params, ext=None)[source]

Write a script that generates a triangle plot. Only intended for use by GetDist.py script.

Parameters:
  • filename – The filename to write to.
  • triangle_params – list of parameter names to plot
  • ext – The extension for the filename, Default if None
writeThinData(fname, thin_ix, cool=1)[source]

Writes samples at thin_ix to file

Parameters:
  • fname – The filename to write to.
  • thin_ix – Indices of the samples to write
  • cool – if not 1, cools the samples by this factor
exception getdist.mcsamples.MCSamplesError[source]

An Exception that is raised when there is an error inside the MCSamples class.

exception getdist.mcsamples.ParamError[source]

An Exception that indicates a bad parameter.

exception getdist.mcsamples.SettingError[source]

An Exception that indicates bad settings.