Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
# pip3 install -r requirements.txt
numpy
scipy
sklearn
scikit-learn
numdifftools
matplotlib
deap
mpi4py
pandas
pyswarms
4 changes: 3 additions & 1 deletion requirements_full.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ numpy
numdifftools
matplotlib
scipy
sklearn
scikit-learn
deap
mpi4py
corner
getdist
pandas
pyswarms
fgivenx
tqdm
4 changes: 2 additions & 2 deletions simplemc/analyzers/GA_deap.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __init__(self, like, model, outputname='deap_output',
self.outputname = outputname
self.params = like.freeParameters()
self.vpars = [p.value for p in self.params]
self.sigma = sp.array([p.error for p in self.params])
self.sigma = np.array([p.error for p in self.params])
self.bounds = [p.bounds for p in self.params]
print("Minimizing...", self.vpars, "with bounds", self.bounds)
self.cov = None
Expand Down Expand Up @@ -147,7 +147,7 @@ def main(self):

# set errors:
#for i, pars in enumerate(self.params):
# pars.setError(sp.sqrt(self.cov[i, i]))
# pars.setError(np.sqrt(self.cov[i, i]))
# update with the final result
#self.result(self.negloglike(self.res.x))

Expand Down
3 changes: 2 additions & 1 deletion simplemc/analyzers/MCEvidence.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
import pandas as pd
import sklearn as skl
import statistics
from sklearn.neighbors import NearestNeighbors, DistanceMetric
from sklearn.neighbors import NearestNeighbors
from sklearn.metrics import DistanceMetric
import scipy.special as sp
from numpy.linalg import inv
from numpy.linalg import det
Expand Down
19 changes: 10 additions & 9 deletions simplemc/analyzers/MCMCAnalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import copy
import random
import sys
import numpy as np
from numpy import loadtxt


Expand Down Expand Up @@ -74,8 +75,8 @@ def __init__(self, like, outfile, skip=5000, nsamp=100000, temp=1.0,
for lb, hb in [p.bounds for p in self.cpars]:
minvals.append(lb)
maxvals.append(hb)
self.minvals = sp.array(minvals)
self.maxvals = sp.array(maxvals)
self.minvals = np.array(minvals)
self.maxvals = np.array(maxvals)
print("Bounds:", self.minvals, self.maxvals)

if (like.name() == "Composite"):
Expand Down Expand Up @@ -143,7 +144,7 @@ def RunChain(self):
if (ploglike > self.cloglike):
accept = True
else:
accept = (sp.exp((ploglike-self.cloglike)/self.temp)
accept = (np.exp((ploglike-self.cloglike)/self.temp)
> random.uniform(0., 1.))

# print [p.value for p in ppars], accept, ploglike
Expand Down Expand Up @@ -229,7 +230,7 @@ def GRDRun(self, chains):
B = lchain/(len(chains)- 1.)*B
R = (1. - 1./lchain)*W + B/lchain

result = sp.array(sp.absolute(1- sp.sqrt(R/W)))
result = np.array(sp.absolute(1- np.sqrt(R/W)))
return result


Expand Down Expand Up @@ -305,8 +306,8 @@ def GetProposal(self):


def draw_pcov(self):
a = sp.array([random.gauss(0., 1,) for _ in range(self.N)])
return sp.dot(a, self.chol)
a = np.array([random.gauss(0., 1,) for _ in range(self.N)])
return np.dot(a, self.chol)



Expand All @@ -324,7 +325,7 @@ def ProcessAccepted(self, ppars, ploglike, ploglikes):

if (self.co > self.skip):
# weight rescaled
wers = self.cw*sp.exp((self.cloglike-self.logofs)
wers = self.cw*np.exp((self.cloglike-self.logofs)
* (self.temp-1.0)/self.temp)

tmp = [wers, -self.cloglike] + vec
Expand Down Expand Up @@ -355,7 +356,7 @@ def ProcessAccepted(self, ppars, ploglike, ploglikes):

elif (self.co < self.skip):
self.swx += self.cw
v = sp.array(vec)
v = np.array(vec)
self.meanx += v*self.cw
self.meanxx += sp.outer(v, v)*self.cw
if (self.cw > 30):
Expand All @@ -370,7 +371,7 @@ def ProcessAccepted(self, ppars, ploglike, ploglikes):
print(self.meanxx)
print()
# for i, p in enumerate(self.cpars):
# print("{}: {} +/- {}".format(p.name, p.value, sp.sqrt(self.meanxx[i, i])))
# print("{}: {} +/- {}".format(p.name, p.value, np.sqrt(self.meanxx[i, i])))

self.init_pcov(self.meanxx)

Expand Down
4 changes: 2 additions & 2 deletions simplemc/analyzers/MaxLikeAnalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(self, like, model, compute_errors=False, compute_derived= False,
self.outputname = outputname
self.params = like.freeParameters()
self.vpars = [p.value for p in self.params]
self.sigma = sp.array([p.error for p in self.params])
self.sigma = np.array([p.error for p in self.params])
self.cov = None
bounds = [p.bounds for p in self.params]
print("Minimizing...", self.vpars, "with bounds", bounds)
Expand Down Expand Up @@ -74,7 +74,7 @@ def __init__(self, like, model, compute_errors=False, compute_derived= False,
print('Covariance matrix \n', self.cov)
# set errors:
for i, pars in enumerate(self.params):
pars.setError(sp.sqrt(self.cov[i, i]))
pars.setError(np.sqrt(self.cov[i, i]))

# update with the final result
self.opt_loglike = self.negloglike(self.res.x)
Expand Down
3 changes: 2 additions & 1 deletion simplemc/analyzers/PSO_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#from pyswarms.utils.plotters import (plot_cost_history,plot_contour,plot_surface)

import scipy as sp
import numpy as np

class PSO_optimizer():
#explain some input params
Expand All @@ -21,7 +22,7 @@ def __init__(self, like, model, outputname='pso_output',

self.params = like.freeParameters()
self.vpars = [p.value for p in self.params]
self.sigma = sp.array([p.error for p in self.params])
self.sigma = np.array([p.error for p in self.params])
self.bounds = [p.bounds for p in self.params]
self.pso_bounds = list(zip(*self.bounds))
print("Minimizing...", self.vpars, "with pso bounds", self.pso_bounds)
Expand Down
2 changes: 1 addition & 1 deletion simplemc/analyzers/dynesty/dynamicsampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1842,7 +1842,7 @@ def computeDerived(self, parname):
sys.exit('Define derived parameter', parname)

def compuAge(self, z):
return 1.0/((1+z)*100.0*self.like.theory_.h*sp.sqrt(self.like.theory_.RHSquared_a(1.0/(1+z))))
return 1.0/((1+z)*100.0*self.like.theory_.h*np.sqrt(self.like.theory_.RHSquared_a(1.0/(1+z))))

class Derivedparam:
def __init__(self, name, value, Ltxname=None):
Expand Down
3 changes: 3 additions & 0 deletions simplemc/chains/LCDM_phy_HD+SN_nested_multi.covmat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
8.642855688074105791e-04,5.420777781013889510e-08,-4.952608240882511691e-04
5.420777781013908039e-08,2.171156857794319018e-07,-6.366617780189736727e-07
-4.952608240882510606e-04,-6.366617780189736727e-07,9.976278146934557719e-04
2 changes: 2 additions & 0 deletions simplemc/chains/LCDM_phy_HD+SN_nested_multi.maxlike
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# -maxlogL
23.910224060351062 0.30184806 0.02201481 0.69264943
6 changes: 6 additions & 0 deletions simplemc/chains/LCDM_phy_HD+SN_nested_multi.paramnames
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Om \Omega_m
Obh2 \Omega_{b}h^2
h h
HD_like HD
BetouleSN_like BetouleSN
theory_prior None
Loading