コード例 #1
0
ファイル: straight_f1.py プロジェクト: chenjj2/Stat_Practice
# n_step = int(5e5)

# hyper_prob0 = np.array([0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.45, 0.6, 0.8])
# hyper_prob0 = np.array([0.5, 0.5, 0.55, 0.5, 0.55, 0.3, 0.5, 0.4, 0.3, 0.45, 0.6, 0.8])
hyper_prob0 = np.loadtxt(hyperic)
hyper_stepsize = (2.0 * 1e-4) * np.ones(3 * n_pop)
local_prob0 = 0.5 * np.ones(n_fixm + 2 * n_varm)
local_stepsize = (2.0 * 1e-4) * np.ones(n_fixm + 2 * n_varm)


hyper_prob_chain, hyper_chain, local_prob_chain, local_chain, loglike_chain, repeat_chain, stop_step = hbm_joint_cdf(
    hyper_prob0,
    hyper_stepsize,
    local_prob0,
    local_stepsize,
    n_step,
    inverse_hyper,
    inverse_local,
    loglike_func,
    data=[dat_fixm, dat_varm],
    trial_upbound=100 * n_step,
)

if np.any(loglike_chain == -np.inf):
    stop_step = np.where(loglike_chain == -np.inf)[0][0]
else:
    stop_step = n_step

if repeat[stop_step - 1] == 0:
    repeat[stop_step - 1] = 1

### save
コード例 #2
0
ファイル: straight_e1.py プロジェクト: chenjj2/Stat_Practice
#n_step = int(5e5)

#hyper_prob0 = np.array([0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.45, 0.6, 0.8])
#hyper_prob0 = np.array([0.5, 0.5, 0.55, 0.5, 0.55, 0.3, 0.5, 0.4, 0.3, 0.45, 0.6, 0.8])
hyper_prob0 = np.loadtxt(input+'hyper_prob_top.out')[0-top,:]
hyper_stepsize = (2.*1e-4) * np.ones(3*n_pop)
local_prob0 = np.loadtxt(input+'local_prob_top.out')[0-top,:]
local_stepsize = (2.*1e-4) * np.ones(n_fixm + 2*n_varm)

np.savetxt(dir+'hyper_prob_start.out', hyper_prob0)
np.savetxt(dir+'local_prob_start.out', local_prob0)

hyper_prob_chain, hyper_chain, local_prob_chain, local_chain, \
loglike_chain, repeat_chain, stop_step = \
hbm_joint_cdf(hyper_prob0, hyper_stepsize, local_prob0, local_stepsize, n_step,\
			inverse_hyper, inverse_local, \
			loglike_func, data = [dat_fixm, dat_varm], \
			trial_upbound = 20*n_step)

### save
np.savetxt(dir+'hyper_prob.out',hyper_prob_chain[:stop_step,:])
np.savetxt(dir+'hyper.out',hyper_chain[:stop_step,:])
np.savetxt(dir+'loglike.out',loglike_chain[:stop_step])
np.savetxt(dir+'repeat.out',repeat_chain[:stop_step])

### save local for debug
np.savetxt(dir+'local_prob.out',local_prob_chain[:stop_step,:])
np.savetxt(dir+'local.out',local_chain[:stop_step,:])

### save top for restart
'''
top_ind = np.argsort(loglike_chain)[-100:]
コード例 #3
0
hyper_domain=hyper_domain, local_domain=local_domain, \
trial_upbound = n_step*10)
'''



### inverse sampling
hyper_prob0 = np.array([0.5, 0.5, 0.5])
local_prob0 = 0.5 * np.ones(2*n_group)
hyper_stepsize = np.array([1e-3, 1e-3, 1e-3])
local_stepsize = 1e-3 * np.ones(2*n_group)

hyper_prob_chain, hyper_chain, local_prob_chain, local_chain, \
loglikelihood_chain, repeat_chain, stop_step = \
hbm_joint_cdf(hyper_prob0, hyper_stepsize, local_prob0, local_stepsize, n_step,\
inverse_hyper, inverse_local,\
loglike_function, data=[mass_ob, mass_err, rad_ob, rad_err],\
trial_upbound = n_step*10)


print 'end', time.asctime()

### plot
row = 2
col = 4

f, ((a00,a01,a02,a03),(a10,a11,a12,a13))=plt.subplots(row,col,figsize=(col*5,row*5))
ax = ((a00,a01,a02,a03),(a10,a11,a12,a13))


# local chain
choice = np.random.choice(np.arange(n_group),5)