In [1]:
import numpy as np
import yaml
from os import path
In [2]:
from pearce.mocks.kittens import TrainingBox
In [3]:
dirname = '/u/ki/swmclau2/des/xi_gg_corrabzheng07/'
In [4]:
with open(path.join(dirname, 'config.yaml'), 'r') as f:
cfg = yaml.load(f)
In [5]:
train_params = np.loadtxt(path.join(dirname, 'trainer_0000.npy'))
In [6]:
HOD_params = np.loadtxt(path.join(dirname, 'HOD_params.npy'))
In [7]:
cfg['HOD']
Out[7]:
In [8]:
cat = TrainingBox(0)
In [9]:
cat.load_catalog(1.0, particles = True)
In [10]:
cat.load_model(1.0, HOD='corrZheng07')#cfg['HOD']['model'])
In [11]:
op_dict= cfg['HOD']['ordered_params']
del op_dict['logMmin']
In [12]:
d = dict(zip(op_dict.keys(), HOD_params[101,:]))
In [13]:
from scipy.optimize import minimize_scalar
def add_logMmin(hod_params, cat, min_ptcl = 100):
"""
In the fixed number density case, find the logMmin value that will match the nd given hod_params
:param: hod_params:
The other parameters besides logMmin
:param cat:
the catalog in question
:return:
None. hod_params will have logMmin added to it.
"""
hod_params['logMmin'] = 13.0 #initial guess
#cat.populate(hod_params) #may be overkill, but will ensure params are written everywhere
def func(logMmin, hod_params):
hod_params.update({'logMmin':logMmin})
return (cat.calc_analytic_nd(hod_params, min_ptcl=min_ptcl) - 5e-4)**2
logMmin_bounds = [12.0, 14.0]
res = minimize_scalar(func, bounds = logMmin_bounds, args = (hod_params,), options = {'maxiter':100}, method = 'Bounded')
# assuming this doens't fail
print 'logMmin', res.x
hod_params['logMmin'] = res.x
In [14]:
add_logMmin(d, cat)
In [15]:
cat.populate(d, min_ptcl = 100)
In [16]:
cat.model.mock._total_abundance
Out[16]:
In [17]:
from scipy.stats import poisson
In [18]:
dist = poisson
In [19]:
dist.isf(np.linspace(0,1,10), 2)
Out[19]:
In [20]:
?? dist.isf
In [21]:
from matplotlib import pyplot as plt
%matplotlib inline
import seaborn as sns
sns.set()
In [22]:
p = np.linspace(0,1,1000)
plt.plot(p, dist.isf(p, 2, loc = 0))
Out[22]:
In [24]:
p = np.linspace(0,1,int(1e6))
d = dist.isf(p, 2)
In [ ]: