API
This page details the methods and classes provided by the SimpleMC
.
Top level interface
- class simplemc.DriverMC.DriverMC(iniFile=None, **kwargs)[source]
Bases:
object
This class is the manager and wrapper between all the analyzers and the pertinent functions. It reads the input parameters or ini file.
- Parameters:
iniFile (ini file) – Text file with ini extension that contains all the settings to SimpleMC. If use this option the following kwargs not are necessary.
chainsdir (str) – Directory for the outputs.
model (str) – Choose the model {LCDOM, LCDMasslessnu, nuLCDM, NeffLCDM, noradLCDM, nuoLCDM, nuwLCDM, oLCDM, wCDM, waCDM, owCDM,” owaCDM, JordiCDM, WeirdCDM, TLight, StepCDM, Spline, PolyCDM, fPolyCDM, Decay, Decay01, Decay05,” EarlyDE, EarlyDE_rd_DE, SlowRDE}
prefact (str) – {phy, pre}
vary8 (bool) – Default False
str (datasets) – Default HD (Hubble distance, i. e. Cosmic Chronometers). You can combine HD+SN+BBAO+Planck+UnionSN+…
analyzername (str) – The name of the analyzer. It can be a sampler: {mcmc, nested, emcee} or a optimizer: {maxlike, ga_deap}
compute_derived (bool) – True generates at the flight some derived parameters (such as Omega_Lambda or Universe Age, and save them in the output text file.
custom_parameters (list) – List of Parameter instances.
custom_function (method) – Custom method that reads a parameter list and a vector x, unzip the list, and return a f(x) in terms of the parameters.
path_to_data (str) – path of a dataset text file.
path_to_cov (str) – path of a covariance matrix text file.
fn (str) – Type of function to use in the likelihood due a custom data {“generic”, “hz”, …}.
- emceeRunner(iniFile=None, **kwargs)[source]
This method calls the emcee library to use ensamble sampler.
- executer(**kwargs)[source]
This is a wrapper of the runners of the analyzer in order to make easier the execution, mainly if is through an ini file. **kwargs from mcmcRunner, nestedRunner, emceeRunner, genetic_deap and maxlikeRunner.
- iniReader(iniFile)[source]
It reads the ini file through configparser.
- Parameters:
iniFile (file .ini) – Text file with settings
- logLike(values)[source]
If the sampler used isn’t the MCMC of MCMCAnalyzer then, we need to set other types of likelihoods and priors objects. This method allows that. It is a likelihood defined for an external samplers and is used as parameter of the sampler run function.
- Parameters:
values (n-dim vector) – implicit values, they are generated by the sampler.
- logPrior(theta)[source]
The natural logarithm of the prior probability.
- Parameters:
theta (tuple) – A sample containing individual parameter values
- mppool(nproc)[source]
It creates a multiprocessing objet to parallelise nested and emcee samplers.
- Parameters:
nproc (int) – number of processors to use.
- Returns:
pool (multiprocessing.Pool) – object
nproc (int) – Number of processes
- nestedRunner(iniFile=None, **kwargs)[source]
This method calls Dynesty nested samplers.
- Parameters:
dynamic (bool) – Default False
nestedType (str) – {single, multi, balls, cubes}
nlivepoints (int) – Number of live points.
accuracy (float) – Stopping criteria in terms of logz.
nproc (int) – Number of processors to parallelize. Use 1 or 0 if you don’t want parallelise.
priortype (str) – Gaussian or uniform prior {‘g’, ‘u’}.
nsigma (float) – Sigma for gaussian priors.
- neuralLike(iniFile=None, **kwargs)[source]
Under construction. This method trains a neural network in order to learn the likelihood function.
- outputChecker()[source]
This method check if the name of the outputfile exists, if it already exists creates a new one with extension _new in its name.
- paramFiles()[source]
This method writes the .paramnames file with theirs LaTeX names.
- Parameters:
T (model) – T is result of ParseModel(model)
L (likelihood) – L is result of ParseDataset(datasets)
- class simplemc.CosmoCalc.CosmoCalc(model, funct=None, param=None, minparam=None, maxparam=None, nsteps=3, savepdf=False, zmax=3, plot_data=False)[source]
Bases:
object
Cosmological calculator to plot the basic functions
- Parameters:
model (object) – Cosmological model.
funct (str) – Chosen function. It can be one of the following: ‘Hubble’, ‘DaOverrd’, ‘HIOverrd’, ‘DVOverrd’, ‘HubInvOverz’, ‘SNIa’, ‘fs8’, ‘Age’.
param (str) – Name of parameter.
minparam (float) – Min value of the chosen parameter.
maxparam (float) – Max value of the chosen parameter.
nsteps (int) – Number of steps to linspace for plot.
savepdf (bool) – Save a plot in pdf.
zmax (float) – Max value to redshift.
plot_data (bool) – Plot observational dataset?
Likelihood
- class simplemc.likelihoods.BaseLikelihood.BaseLikelihood(name)[source]
Bases:
object
This is the base likelihood object. Base for all other likelihoods.
- class simplemc.likelihoods.CompressedSNLikelihood.BetouleSN[source]
Bases:
simplemc.likelihoods.CompressedSNLikelihood.CompressedSNLikelihood
Likelihood to binned JLA dataset.
- class simplemc.likelihoods.CompressedSNLikelihood.CompressedSNLikelihood(name, values_filename, cov_filename)[source]
Bases:
simplemc.likelihoods.BaseLikelihood.BaseLikelihood
This module calculates likelihood for the compressed SN.
- class simplemc.likelihoods.CompressedSNLikelihood.UnionSN[source]
Bases:
simplemc.likelihoods.CompressedSNLikelihood.CompressedSNLikelihood
Likelihood to binned Union 2.1 dataset
Cosmo
- class simplemc.cosmo.Parameter.Parameter(name, value, err=0.0, bounds=None, Ltxname=None)[source]
Bases:
object
A simple class for dealing with Parameter. Parameter has a name, a value, an error and some bounds Names have also latex names.
- Parameters:
name (str) – Name to identify the parameter.
value (float) – Default value. In MCMC will be the starting value.
err (float) – Estimated error, in MCMC will be the step of the chain. Default is 0, but better to write any positive number.
bounds (list) – Priors. (minimum value, maximum value). List of pairs of bounds. Default is None, but computed as ‘(value-5*err, value+5*err)’.
Ltxname (str) – Latex name, use mainly for plotting. Default is None, and in this case uses the ‘name’ string.
Example
The hubble parameter h_par = Parameter(‘h’, 0.6821, 0.05, (0.4, 1.0), ‘h’)
- class simplemc.cosmo.BaseCosmology.BaseCosmology(h=0.6821)[source]
Bases:
object
Base Cosmology class doesn’t know about your parameterization of the equation of state or densities or anything. However, it does know about Hubble’s constant at z=0 OR the prefactor c/(H0*rd) which should be fit for in the case of “rd agnostic” fits. That is why you should let it declare those parameters based on its settings
However, to get the angular diameter distance you need to pass it its Curvature parameter (Omega_k basically), so you need to update it.
Also to use fs8 dataset you need to add s8 parameter.
We use speed of light in km s^-1.
- Parameters:
h (float) – Value of the Hubble parameter h = H/100.
- class simplemc.cosmo.RadiationAndNeutrinos.RadiationAndNeutrinos(mnu=0.06, Nnu=3.046, varyMnu=False, varyNnu=False, degenerate=False, disable=False)[source]
Bases:
object
Class for neutrinos, Mnu and Nnu
- Parameters:
mnu (float) – Standard value for the mass of neutrinos.
Nnu (float) – Standard value for the number of families.
varyMnu (bool) – Whether varying mass for neutrinos.
varyNnu (bool) – Whether varying families for neutrinos.
degenerate (bool) – Degenerate neutrinos.
disable (bool) – Set radiation to zero.
- class simplemc.cosmo.NuDensity.NuDensity(TCMB, Nnu=3.046, mnu=0.06, degenerate=False, fact=None)[source]
Bases:
object
Compute Density parameter for neutrinos.
- Parameters:
TCMB (float) – Temperature of the CMB.
Nnu (float, optional) – Families of neutrinos. Default value is ‘Neff=3.046’.
mnu (float, optional) – Sum of the neutrino masses. Default value is ‘mnu=0.06’.
degenerate (bool, optional) – Combinations of massive neutrinos.
fact (float, optional) – The ratio contribution: omrad_fac = 4.48130979e-7.
- class simplemc.cosmo.NuDensity.NuIntegral[source]
Bases:
object
This module calculates the predictions for the evolution of neutrino energy densities. Here, we compute the integral I(r). Initialiazes the nu factor in rho_nu (self.interpolator).
- class simplemc.cosmo.NuDensity.ZeroNuDensity[source]
Bases:
object
Fake class that returns zeros if want to disable neutrino contributions.
- class simplemc.cosmo.Derivedparam.AllDerived[source]
Bases:
object
Given base parameters, return a list of some Derived ones.
- Omh2(z1, z2)[source]
Computes the Omh2 diagnostic at two redshifts to test deviations from the LCDM model. For LCDM the value is a constant for any combination of redshifts.
- class simplemc.cosmo.Derivedparam.Derivedparam(name, value, Ltxname=None)[source]
Bases:
object
Auxiliary class, based on Parameter class.
- Parameters:
name (string) – Parameter name.
value (float) – Initialize the value, and use a function to update it.
Ltxname (string, optional) – Provides the Latex name, useful for plotting. Default is None, and in this case uses the ‘name’ string.
Example
Hubble parameter self.H0 = Derivedparam(‘H0’, function, ‘H_0*’)
Models
- class simplemc.models.LCDMCosmology.LCDMCosmology(Obh2=0.02234, Om=0.3038, h=0.6821, mnu=0.06, Nnu=3.046, degenerate_nu=False, disable_radiation=False, fixOm=False)[source]
Bases:
simplemc.cosmo.BaseCosmology.BaseCosmology
,simplemc.cosmo.RadiationAndNeutrinos.RadiationAndNeutrinos
This is LCDM cosmology, it is used as a base class for most other cosmologies, mostly because it treats Neutrinos and Radiation hassle.
- Parameters:
Obh2 (float) – Barionic matter: Omega_bh^2
Om (float) – Matter density.
h (float) – Hubble parameter H/100.
mnu (float) – Standard value for the mass of neutrinos.
Nnu (float) – Standard value for the number of families.
degenerate_nu (bool) – Degenerate neutrinos.
disable_radiation (bool) – Without radiation.
fixOm (bool) – Om constant.
- class simplemc.models.owa0CDMCosmology.owa0CDMCosmology(varyw=True, varywa=True, varyOk=True)[source]
Bases:
simplemc.models.LCDMCosmology.LCDMCosmology
This is CDM cosmology with w, wa and Ok. CPL parameterization with curvature. This class inherits LCDMCosmology class as the rest of the cosmological models already included in SimpleMC.
- Parameters:
varyw (Boolean) – variable w0 parameter
varywa (Boolean) – variable wa parameter
varyOk (Boolean) – variable Ok parameter
Analyzers
- class simplemc.analyzers.MCMCAnalyzer.MCMCAnalyzer(like, outfile, skip=5000, nsamp=100000, temp=1.0, cov=None, chain_num=None, addDerived=False, GRstop=0.01, checkGR=500)[source]
Bases:
object
MCMC sampler (Metropolis-Hastings). This is the MCMC module. It spits out chains that are compatible with CosmoM it calculates cov matrix during burn-in. optional temperature makes it sample at a higher temperature but note that this guy, as opposed to cosmomc, reweights the weights on the fly.
- Parameters:
like (Likelihood object) – Object of a Likelihood class.
outfile (str) – Output file.
skip (int) – Burn-in.
nsamp (int) – Number of mcmc samples.
temp (float) – Temperature
cov (numpy.array) – Covariance matrix. Default: None.
addDerived (bool) – In order to ad derived parameters such as age of the universe and Omega_{Lambda}.
GRstop (float) – Gelman-Rubin criteria.
- class simplemc.analyzers.MaxLikeAnalyzer.MaxLikeAnalyzer(like, model, compute_errors=False, compute_derived=False, show_contours=False, plot_param1=None, plot_param2=None, outputname=None)[source]
Bases:
object
This is an analyzer that takes a Likelihood function and then tries to maximize it with L-BFGS-B method and get the errors from the second derivative matrix. It kinda works, but not very well.
- Parameters:
- class simplemc.analyzers.GA_deap.GA_deap(like, model, outputname='deap_output', population=20, crossover=0.7, mutation=0.3, max_generation=20, hof_size=1, crowding_factor=1, plot_fitness=False, compute_errors=False, show_contours=False, plot_param1=None, plot_param2=None)[source]
Bases:
object
Genetic algorithms from deap library
- Parameters:
like – likelihood function
model – theoretical model model
plot_fitness – True if you want to generate a plot of the fitness.
compute_errors – True if you want to compute errors.
show_contours – True if you want to show the contours in a plot.
plot_param1 – a parameter to plot in x-axis.
plot_param2 – a parameter to plot in y-axis.
- class simplemc.analyzers.neuralike.NeuralManager.NeuralManager(loglikelihood, pars_bounds, rootname, ndivsgrid=5, hidden_layers_neurons=None, epochs=100, plot=True, **kwargs)[source]
Bases:
object
Manager for neural networks to learn likelihood function over a grid :param loglikelihood: :param pars_bounds: :param rootname: :param ndivsgrid: :param hidden_layers_neurons: :param epochs: :param plot:
We use several nested sampling algorithms included in dynesty
library. We slightly modify dynesty
to save the strings in the text file and also to incorporate neural networks. However, its documentation is very complete, clear and didactic, so we recommend that you visit it.
Plots
- class simplemc.plots.Simple_Plots.Simple_plots(dir_name, roots, label=None, **kwargs)[source]
Bases:
simplemc.tools.cosmich.cosmochain
Collection of plotters.
- Parameters:
- Plots1D(params, **kwargs)[source]
1D posterior plots. :param params: parameters to plot. :type params: list
- Plots2D(params_pair, **kwargs)[source]
2D posterior plots between two parameters.
- Parameters:
params_pair (list) – pair of parameters to 2D plots.
kwargs – pbest: boolean, solid: boolean.
- cornerPlotter(params, color='g', show_titles=True, fill_contours=True)[source]
Triangle plot using corner library.
- Parameters:
params – list of parameters
color – color, eg. ‘c’, ‘b’, etc.
show_titles – True if you want to show tittles.
fill_contours – True if you want to fill the contours.