-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel7.py
executable file
·52 lines (40 loc) · 1.44 KB
/
model7.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import pickle
import numpy
import pystan
# one color parameter model setting <k>=0, <kk>=1
pkl_file = open('gege_data.pkl', 'r')
data = pickle.load(pkl_file)
pkl_file.close()
# The ordering is 'Ca','Si','U','B','V','R','I'
EW_obs = data['obs'][:,0:2]
mag_obs = data['obs'][:,2:]
EW_cov = data['cov'][:,0:2,0:2]
mag_cov = data['cov'][:,2:,2:]
nsne, nmags = mag_obs.shape
# # renormalize the data
EW_mn = EW_obs.mean(axis=0)
EW_renorm = (EW_obs - EW_mn)
mag_mn = mag_obs.mean(axis=0)
mag_renorm = mag_obs-mag_mn
data = {'D': nsne, 'N_mags': 5, 'N_EWs': 2, 'mag_obs': mag_renorm, 'EW_obs': EW_renorm, 'EW_cov': EW_cov, 'mag_cov':mag_cov}
Delta_simplex = numpy.zeros(nsne)+1./nsne
k_simplex = ((-1.)**numpy.arange(nsne)*.25 + .5)*2./nsne
init = [{'EW' : EW_renorm, \
'c': numpy.zeros(5),\
'alpha': numpy.zeros(5), \
'beta':numpy.zeros(5), \
'gamma0': 0.1,\
'gamma_': numpy.zeros(4), \
'mag_int': mag_renorm, \
'L_sigma': numpy.zeros(5)+0.05, \
'L_Omega': numpy.identity(5), \
'Delta_unit':Delta_simplex, 'Delta_scale': nsne/8.,\
'k_unit': k_simplex} \
for _ in range(4)]
sm = pystan.StanModel(file='gerard7.stan')
control = {'stepsize':1.}
fit = sm.sampling(data=data, iter=2000, chains=4,control=control,init=init,thin=2)
print fit
output = open('temp7.pkl','wb')
pickle.dump(fit.extract(), output)
output.close()