Ejemplo n.º 1
0
state_params["observation_groups"]     = problem.get_obs_groups()
state_params["simulation_function"]    = problem.simulation_function
state_params["statistics_function"]    = problem.statistics_function
state_params["response_groups"]        = [Kernel( kernel_params )]


mcmc_params = {}
mcmc_params["priorrand"]       = problem.theta_prior_rand
mcmc_params["logprior"]        = problem.theta_prior_logpdf
mcmc_params["proposal_rand"]   = problem.theta_proposal_rand
mcmc_params["logproposal"]     = problem.theta_proposal_logpdf
mcmc_params["is_marginal"]     = False
mcmc_params["nbr_samples"] = nbr_samples

theta0 = problem.theta_prior_rand()
state  = State( 0.1+0*theta0, state_params )
loglik = state.loglikelihood()
recorder = Recorder()
recorder.record_state( state, state.nbr_sim_calls, accepted=True )

print "***************  RUNNING ABC MCMC ***************"
thetas, LL, acceptances,sim_calls = abc_mcmc( mcmc_params, state, recorder  )
print "***************  DONE ABC MCMC    ***************"

print "***************  VIEW RESULTS ***************"
problem.view_results( recorder, burnin = nbr_samples/2 )
pp.show()
print "***************  DONE VIEW    ***************"

print "TODO"
print "verify kernel epsilon on stats"
Ejemplo n.º 2
0
state_params["simulation_function"] = problem.simulation_function
state_params["statistics_function"] = problem.statistics_function
state_params[
    "zero_cross_terms"] = True  # change this if we want diagonal estimates
#state_params["log_kernel_func"]            = log_gaussian_kernel
state_params["is_marginal"] = False
state_params["epsilon"] = 0.5  #np.array([0.1,0.1,0.1,1.0])
#state_params["hierarchy_type"]             = "jeffreys"
state_params["hierarchy_type"] = "just_gaussian"
nbr_samples = 100
reject_epsilon = 5.0

rej_state_params = state_params.copy()
rej_state_params["S"] = 1
rej_state = RejectState(None, rej_state_params)
recorder = Recorder(record_stats=True)
n_reject = 1
print "***************  RUNNING REJECTION ***************"
rej_thetas, rej_discs = abc_rejection(n_reject,
                                      reject_epsilon,
                                      rej_state,
                                      recorder=recorder)
theta0 = rej_thetas[-1]
#theta0 = np.array([ 3.07687576, -0.86457619,  6.1387475 , -3.85783667, -0.40429067,  9.        ])

state = State(theta0, state_params)

model = MH_Model(model_params)
model.set_current_state(state)
model.set_recorder(recorder)