Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lot of things #6

Open
wants to merge 140 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
140 commits
Select commit Hold shift + click to select a range
8d0b551
added module to analyze chains. CosmoHammer autocorr.
Oct 30, 2017
d00d8b5
added Goodman&Weare autocor., plot method, R-1, fixed read MP chains (no
Oct 31, 2017
e262807
added option to keep first columns in readChain
Nov 2, 2017
dfef1fd
added functions to obtain tau_int
Nov 2, 2017
975da05
added function to return tau_exp
Nov 2, 2017
f6658ea
fixed error in multiplicity readChain
Nov 3, 2017
4cee672
modified getGelmanRubin
Nov 3, 2017
4367d2b
added method to copute tau_exp for a list of paramIndexes, and plot it
Nov 3, 2017
0a6435f
added method to empty chains
Nov 3, 2017
f20db8c
added option to plot normalized autocorr.
Nov 3, 2017
480eeed
added error when free parameter is wrong a causes error at reading chain
Nov 3, 2017
688721f
join burnin+sample in CH. Needed for C(T)
Nov 6, 2017
00a4507
use np.logspace instead of np.linspace for pk
Nov 10, 2017
698cbbf
modified optional argument acordingly to previous commit
Nov 10, 2017
f276c0f
rewritten compute_lkl in a more sensible way
Nov 30, 2017
26d1873
fixed comment parsing bug
Nov 30, 2017
0e1bccb
improved error printing
Jan 17, 2018
ec40755
initial commit. untested program. supposed to work. Just compute bins
Jan 30, 2018
617dbbe
fixed typo error
Jan 30, 2018
53847ab
fixed typo error in computed
Jan 30, 2018
a9a94d3
fixed path variable in read_file method
Jan 30, 2018
b61f18d
seem to work ok for quintessence Marsh project files
Jan 31, 2018
5388653
changed print to sys.stdout/err.write and added destination folder op…
Jan 31, 2018
8963c2e
fixed wrong call to save_computed
Jan 31, 2018
b9c8af3
reversed order of cleaning cosmo to avoid memory leakages
Jan 31, 2018
06cc43b
module to obtain and plot histograms from binned variables
Feb 2, 2018
f71331e
improved plot_evolution
Feb 2, 2018
488e5fc
computation made modular
Feb 5, 2018
29d691b
removed old things and added method to increase filename numbering if…
Feb 6, 2018
73e8133
initial commit. Works for quintessence models
Feb 6, 2018
0b7271f
fixed phi_prime_ini =0 error and minor changes
Feb 7, 2018
39b5841
removed means,sigma computation, added method for correlation
Feb 7, 2018
e82d07c
fixed error in sigma computation
Feb 7, 2018
d118662
added method correlation, fixed naming error in covariance, added plo…
Feb 8, 2018
55c39ef
added method to reflex histograms and lognorm in evolution plot
Mar 5, 2018
7fa5085
added method to rebin histograms to unit variance
Mar 5, 2018
ccb798a
center reflected histograms
Mar 5, 2018
4ea1793
corrected histogram reflection
Mar 6, 2018
60f0181
removed method to rebin s.t. var=1. Better initizalize new class with…
Mar 6, 2018
eb4b658
added different monomials. Also integers, odds, evens
Mar 12, 2018
aa5cb6b
added log scalar sampling for phi_ini monomial
Mar 14, 2018
46965e7
fixed params storing
Mar 14, 2018
2396016
fixed monomial exponential limit and added CC term for eft
Mar 14, 2018
03bad60
save shooting variable values also
Mar 19, 2018
7b578e8
added inversed monomials and large EF in EFT
Mar 19, 2018
1a9db79
added option to output Pade coefficients
Mar 21, 2018
8456ffc
moved errors
Mar 21, 2018
03798c4
corrected Pade function
Mar 21, 2018
36dbdb5
fixed shooting_parameter saving
Mar 22, 2018
77f1c5e
fixed missing e in Exception as e
Mar 22, 2018
bffb076
added Emilio's code for arbitrary order Pade fit
Mar 22, 2018
a776f1c
added option to save plots
Apr 4, 2018
f1d1811
updated for Pade and new cases
Apr 4, 2018
980827d
added differential at X from three points
Apr 4, 2018
3e03565
Added binning and histograms modules from HP project
Apr 4, 2018
53b3de6
moved binning and histograms modules to module folder
Apr 4, 2018
d874c89
added reflect_data function
Apr 4, 2018
968e4ef
added title option for plot_evolution
Apr 6, 2018
57028bc
moved fit_pade to wicmth
Apr 10, 2018
3b8b9e8
modified fit_pade, added p0_calc, changed accordingly binning.py
Apr 12, 2018
f924ce7
fixed error + added informative header to Pade output file
Apr 12, 2018
d48677f
added missing \n
Apr 12, 2018
f110f79
added kwards to fit_pade and option to modify maxfev in binning
Apr 16, 2018
94b5ec0
reduce order of Pade approx if fit fails
Apr 18, 2018
4b683d6
raise error if all tries in fit are exhausted
Apr 18, 2018
eb2f142
modified Pade header and its reading in histograms.py
Apr 23, 2018
9d2bef4
fixed white space Pade header
Apr 23, 2018
8d1715b
improved plot_correlation_matrix
Apr 23, 2018
4b41df6
more complex change of Pade order in fit
Apr 27, 2018
9f69e1b
added option to display or not the figures
Apr 27, 2018
16ddd53
added plot_covariance_matrix
Apr 27, 2018
8b4611e
Pade coeffs increasing number
May 17, 2018
921e48e
use acor by default. cains type is np.array now
May 30, 2018
cab4ae7
added lists for params names and method to read them
Jun 6, 2018
a3358cf
added function to output cosmo params for classy for failed steps
Jun 7, 2018
70f5fe0
updated readCosmoHammerChain, use slicing
Jun 8, 2018
e11a851
modified readCosmoHammerChains to read list of chain paths
Jun 11, 2018
4116c92
rearrange the getCosmoParams functions and store cosmo_arguments values
Jun 18, 2018
0bb9ba4
take into account param scale
Jun 18, 2018
b6242e6
added Taylor fit to F(a)=\int dlna w function
Jul 2, 2018
50c29cd
added general fit function and Taylor expansion
Jul 2, 2018
08781d3
implemented output for f fit
Jul 2, 2018
1f7b0f8
fixed typo
Jul 2, 2018
215b3b2
fixed lot of bugs in f computation
Jul 2, 2018
f00dfce
reset before setting specific options
Jul 2, 2018
c52cdcf
improved rel. dev. for f and use Simpson's integration for DA
Jul 2, 2018
c1d8995
added option to fix to 0 the zeroth order Taylor coeff
Jul 3, 2018
18e4c91
changed RK45 to LSODA in growth rate integration
Jul 4, 2018
2f4b524
fixed header fit coeffs
Jul 5, 2018
086638f
added set_fit function to manage general fit
Jul 12, 2018
bb67694
added compute_fit_from_params that generalizes previous ones
Jul 12, 2018
b650cd6
implemented output_files for general fit, splitted file generation
Jul 13, 2018
b7f818f
removed old method for file name generation
Jul 13, 2018
3289d85
removed old method for Taylor fitting
Jul 13, 2018
a87e16a
changed Taylor for fit_function
Jul 13, 2018
029034e
added method to compute DA and f max.rel.dev.
Jul 13, 2018
6461c42
cleant a bit the code
Jul 13, 2018
b58d08b
removed old compute_f_from_params
Jul 13, 2018
ba09c79
changed method name
Jul 13, 2018
a87ccf0
add method with common initial steps in compute_fit_
Jul 13, 2018
31e0c22
added compute_fit_for_w method
Jul 13, 2018
657291f
generalized fit function
Jul 17, 2018
d829d8b
Added method to fit logX = log(rho/rho_0)
Jul 24, 2018
d296cbd
new file for DA and f
Jul 25, 2018
faa2955
fixed w in compute_coeffs_for_logX
Jul 25, 2018
2ecc9af
added factorial factors in Taylor expansion for have coeffs in fit O(1)
Jul 25, 2018
828413b
added Taylor_legacy for compatibility with old runs
Jul 25, 2018
9fe3e2b
fixed w sign
Jul 25, 2018
0a3f46d
fixed missin = in <= slicing
Jul 25, 2018
fa73d12
added method to fit log(rho_de)
Jul 26, 2018
520e8fd
updated filenames
Aug 30, 2018
e08c0c2
added Pade function to test binning
Sep 14, 2018
8732223
Pade coeffs scaled by factorial of magnitude order
Sep 18, 2018
2fdce01
added log-modulus
Oct 11, 2018
1a299be
added sample_log_data function
Oct 12, 2018
9a06454
added inverse function of log_modulus
Oct 15, 2018
c9aa913
add dollar for latex in labels
Oct 15, 2018
7f2ce6e
fixed error in xlabel/ylabel latex
Oct 16, 2018
7b8c6c3
automatize usage of latex for bin labels
Oct 17, 2018
61345a7
added log_complex and inverse functs
Oct 19, 2018
ed4b30c
added method to output hist in diagonalized cov. matrx. basis
Oct 22, 2018
c3cacc4
fixed numpy array type
Oct 22, 2018
31c4106
compute covariance matrix if not computed already
Oct 22, 2018
c218790
just transform data, not compute hists nor cov. matrix
Oct 22, 2018
6543462
Added polynomial exp. with logM inverse as coeffs
Oct 22, 2018
7930713
added Taylor with c0=0
Oct 24, 2018
844f9fc
Implemented fitting of X
Oct 25, 2018
02a251f
Implemented different temporal variables
Oct 25, 2018
b05438b
Added info of temporal variable in files' header.
Oct 25, 2018
f18ed0b
Fixed error with w_fit fitting X.
Oct 25, 2018
55ecb0a
Implemented (1-a) for tmp variable
Oct 25, 2018
27d79d2
Interpolate before instead of approxiamatin yfi1 intermediate values.
Oct 25, 2018
3999364
return np.array in log sampling
Oct 26, 2018
a515b56
Adde Taylor_legacy_c0
Oct 30, 2018
31a0793
added Taylor_c1
Nov 13, 2018
61ad904
Multiply per 100 to have %
Nov 24, 2018
3817cbe
check if negatives before log(-x)
Nov 27, 2018
15756a6
added bins_evenly_spaced function
Nov 29, 2018
551fc8f
normalize colorbar correlation matrix
Dec 14, 2018
a9c2b93
added option to compute DA only at certain redshifts
Jan 22, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
821 changes: 821 additions & 0 deletions work_in_class/binning.py

Large diffs are not rendered by default.

442 changes: 442 additions & 0 deletions work_in_class/chain_analyzer.py

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions work_in_class/compute_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def add_derived(self, varied_name, keys, value):

def compute_models(self, params, varied_name, index_variable, values,
back=[], thermo=[], prim=[], pert=[], trans=[],
pk=[0.0001, 0.1, 100], extra=[], update=True,
pk=[-4, -1, 100], extra=[], update=True,
cosmo_msg=False, texname=""):
"""
Fill dic with the hi_class output structures for the model with given
Expand Down Expand Up @@ -157,7 +157,7 @@ def compute_models(self, params, varied_name, index_variable, values,
except Exception, e:
print "Error: skipping {}={}".format(key, val)
if cosmo_msg:
print e
print str(e) + '\n'

continue

Expand Down Expand Up @@ -222,9 +222,8 @@ def compute_models(self, params, varied_name, index_variable, values,
except CosmoSevereError:
pass


if ("output" in self.cosmo.pars) and ('mPk' in self.cosmo.pars['output']):
k_array = np.linspace(*pk)
k_array = np.logspace(*pk)
pk_array = np.array([self.cosmo.pk(k, 0) for k in k_array])

d['pk'] = {'k': k_array, 'pk': pk_array}
Expand Down
50 changes: 50 additions & 0 deletions work_in_class/cosmo_extra.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/python
import numpy as np
from classy import CosmoSevereError
import scipy.integrate as integrate

#####
# NOTE: Emilio's functions from classy.pyx. self should not be used like this, but let's do an exception.
#####

def growthrate_at_k_and_z(cosmo, k, z):
dz = 0.005
f=-0.5*(1+z)*(-3.*np.log(cosmo.pk(k,z))+4.*np.log(cosmo.pk(k,z+dz))-np.log(cosmo.pk(k,z+2.*dz)))/(2.*dz)
if (f==0.):
raise CosmoSevereError(
"The step in redshift is too small to compute growth rate")
return f

def growthrate_at_z(cosmo, z):
k_fid = 0.01
return growthrate_at_k_and_z(cosmo, k_fid, z)
#########

def fprime(OmegaDEw, OmegaM):
"""
Return function df/dz(z, f).

OmegaDEw and OmegaM must be functions of z
"""
def wrap(z, f):
try:
#output = 1.5 * OmegaM(z) - 0.5 * (1 - 3*w(z)*OmegaDE(z)) * f - f**2
output = ((0.5 * (1 - 3*OmegaDEw(z))) * f + f**2 - 1.5 * OmegaM(z)) / (1+z)
except Exception as e:
raise e
return output
return wrap
def angular_distance(z, H, z_points=None):
"""
Return the angular distance.
z, H must be CLASS-like arrays
"""
DA_fit = []
if z_points is None:
z_points = z

for i in z_points:
#DA_fit.append(1/(1+i)*integrate.trapz(1/H_fit[zTMP<=i][::-1], zTMP[zTMP<=i][::-1]))
DA_fit.append(1/(1+i)*integrate.simps(1/H[z <= i][::-1], z[z <= i][::-1], even='last'))

return np.array(DA_fit)
24 changes: 14 additions & 10 deletions work_in_class/data_mp_likelihoods.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def remove_experiments(self, experiments):

for exp in self.__name_str_to_list(experiments):
if exp in self.experiments:
self.experiments.remove(experiment)
self.experiments.remove(exp)

def get_mcmc_parameters(self, table_of_strings):
"""
Expand Down Expand Up @@ -298,8 +298,9 @@ def clear(self, params=''):
self.mcmc_parameters.clear()

def compute_lkl(self, cosmo, params, experiments=[], nuisance=[], overwrite=False, cosmo_struct_cleanup=False):
"""Compute the likelihood for the parms given. Params will update the
cosmo_arguments and nuisance_parameters unless overwrite is True.
"""Compute the likelihood for the parms and experiments given. Params
will update the cosmo_arguments and nuisance_parameters unless overwrite
is True. If no experment is passed, it will used the initialised ones.

For the time being, params must be given in classy form.

Expand All @@ -315,24 +316,27 @@ def compute_lkl(self, cosmo, params, experiments=[], nuisance=[], overwrite=Fals
them could have been set by the experiments so that \
their removal will likely cause an error."
self.clear()
else:
self.clear("cosmo")

if not experiments:
experiments = self.experiments

lkl = 0
for experiment in self.__name_str_to_list(experiments):
if experiment not in self.experiments:
print "Adding {} to list of initialised experiments".format(experiment)
self.add_experiments([experiment], nuisance)
else:
for experiment in self.__name_str_to_list(experiments):
if experiment not in self.experiments:
print "Adding {} to list of initialised experiments".format(experiment)
self.add_experiments([experiment], nuisance)

# set and compute must be called after initializing the lkl's. Some of them add
# some mandatory parameters (e.g. {'output': 'mPk'}).

self.update_params(params)
cosmo.empty()
cosmo.set(self.__params_to_cosmo_classy()) # TODO: Modify to accept params as in MP input
cosmo.compute()

for experiment in self.experiments:
lkl = 0
for experiment in experiments:
lkl += self.lkl[experiment].loglkl(cosmo, self)

if cosmo_struct_cleanup:
Expand Down
Loading