Cosmological constraints with SNeIa
Description
Example written in Python to obtain constraints (best-fit and covariance
matrix) on the cold dark matter density $\Omega_c$ and the dark energy
equation of state $w$ parameters, where $w =$ constant, using type Ia supernova
(SNeIa) data. In this case, the covariance matrix is obtained via observed
Fisher Matrix approach.
Running
To try this example you must have PyGObject installed ,
and numcosmo built with –enable-introspection option. To run the examples
without installing follow the instructions here .
#!/usr/bin/python2
try :
import gi
gi . require_version ( 'NumCosmo' , '1.0' )
gi . require_version ( 'NumCosmoMath' , '1.0' )
except :
pass
from math import *
import matplotlib.pyplot as plt
from gi.repository import GObject
from gi.repository import NumCosmo as Nc
from gi.repository import NumCosmoMath as Ncm
#
# Initializing the library objects, this must be called before
# any other library function.
#
Ncm . cfg_init ()
#
# New homogeneous and isotropic cosmological model NcHICosmoDEXcdm
#
cosmo = Nc . HICosmo . new_from_name ( Nc . HICosmo , "NcHICosmoDEXcdm" )
#
# Setting values for the cosmological model, those not set stay in the
# default values. Remeber to use the _orig_ version to set the original
# parameters in case when a reparametrization is used.
#
#
# OO-like
#
cosmo . props . H0 = 70.0
cosmo . props . Omegab = 0.05
cosmo . props . Omegac = 0.25
cosmo . props . Omegax = 0.70
cosmo . props . Tgamma0 = 2.72
cosmo . props . w = - 1.0
#
# Creating a new Modelset and set cosmo as the HICosmo model to be used.
#
mset = Ncm . MSet ()
mset . set ( cosmo )
#
# Setting parameters Omega_c and w to be fitted.
#
cosmo . props . Omegac_fit = True
cosmo . props . w_fit = True
#
# Creating a new Distance object optimized to redshift 2.
#
dist = Nc . Distance ( zf = 2.0 )
#
# Creating a new Data object from distance modulus catalogs.
#
snia = Nc . DataDistMu . new_from_id ( dist , Nc . DataSNIAId . SIMPLE_UNION2_1 )
#
# Creating a new Dataset and add snia to it.
#
dset = Ncm . Dataset ()
dset . append_data ( snia )
#
# Creating a Likelihood from the Dataset.
#
lh = Ncm . Likelihood ( dataset = dset )
#
# Creating a Fit object of type NLOPT using the fitting algorithm ln-neldermead to
# fit the Modelset mset using the Likelihood lh and using a numerical differentiation
# algorithm (NUMDIFF_FORWARD) to obtain the gradient (if needed).
#
fit = Ncm . Fit . new ( Ncm . FitType . NLOPT , "ln-neldermead" , lh , mset , Ncm . FitGradType . NUMDIFF_FORWARD )
#
# Running the fitter printing messages.
#
fit . run ( Ncm . FitRunMsgs . SIMPLE )
#
# Printing fitting informations.
#
fit . log_info ()
#
# Calculating the parameters covariance using numerical differentiation.
#
fit . numdiff_m2lnL_covar ()
#
# Printing the covariance matrix.
#
fit . log_covar ()
#----------------------------------------------------------------------------------
# Model fitting. Interating using:
# - solver: NLOpt:ln-neldermead
# - differentiation: Numerical differentiantion (forward)
#.............
# Minimum found with precision: |df|/f = 1.00000e-08 and |dx| = 1.00000e-05
# Elapsed time: 00 days, 00:00:00.0102450
# iteration [000047]
# function evaluations [000048]
# gradient evaluations [000000]
# degrees of freedom [000577]
# m2lnL = 562.21916535683 ( 562.21917 )
# Fit parameters:
# 0.230588641762734 -1.02987350210547
#----------------------------------------------------------------------------------
# Data used:
# - Union2.1 sample
#----------------------------------------------------------------------------------
# Model[00000]:
# - NcHICosmo : XCDM - Constant EOS
#----------------------------------------------------------------------------------
# Model parameters
# - H0[00]: 70 [FIXED]
# - Omegac[01]: 0.230588641762734 [FREE]
# - Omegax[02]: 0.7 [FIXED]
# - Tgamma0[03]: 2.72 [FIXED]
# - Yp[04]: 0.24 [FIXED]
# - ENnu[05]: 3.046 [FIXED]
# - Omegab[06]: 0.05 [FIXED]
# - w[07]: -1.02987350210547 [FREE]
#----------------------------------------------------------------------------------
# NcmMSet parameters covariance matrix
# -------------------------------
# Omegac[00000:01] = 0.2306 +/- 0.07183 | 1 | -0.9052 |
# w[00000:07] = -1.03 +/- 0.1301 | -0.9052 | 1 |
# -------------------------------