Пример #1
0
mcmc_params["xi"]                = 0.1
mcmc_params["M"]                 = 10
mcmc_params["deltaS"]            = 1
mcmc_params["max_nbr_tries"]     = 10
mcmc_params["acquisition_model"] = AcquisitionModel(acquistion_params)

model = MH_Model( mcmc_params)


#epsilon     = 0.5
theta0 = problem.theta_prior_rand()
#theta0 *=0
#theta0 += 0.1
state  = State( theta0, state_params )

recorder = Recorder(record_stats=True)

#recorder.record_state( state, state.nbr_sim_calls, accepted=True )

model.set_current_state( state )
model.set_recorder( recorder )
loglik = state.loglikelihood()

#recorder.record_state( state, state.nbr_sim_calls, accepted=True )

print "***************  RUNNING SL MCMC ***************"
thetas, LL, acceptances,sim_calls = abc_mcmc( nbr_samples, model, verbose = True  )
print " ACCEPT RATE = %0.3f"%(recorder.acceptance_rate())
print "***************  DONE ABC MCMC    ***************"

print "***************  VIEW RESULTS ***************"
Пример #2
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"
Пример #3
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)
Пример #4
0
mcmc_params["nbr_samples"]       = nbr_samples
mcmc_params["xi"]                = 0.1
mcmc_params["M"]                 = 100
mcmc_params["deltaS"]            = 2
mcmc_params["max_nbr_tries"]     = 10
mcmc_params["acquisition_model"] = AcquisitionModel(acquistion_params)

model = MH_Model( mcmc_params)

print "***************  RUNNING ABC REJECTION ***************"
lower_epsilon = -epsilon*10
upper_epsilon = epsilon*10

theta0 = problem.theta_prior_rand()
state  = DiscState( theta0, state_params )
abc_recorder = Recorder(record_stats=True)
thetas, discs = abc_rejection( 2, lower_epsilon, upper_epsilon, state, problem.theta_prior_rand, abc_recorder  )

initX = thetas.copy()
initY = abc_recorder.get_statistics()[:,0].reshape((len(initX),1))

pgp.add_data( initX, initY )
#gp.optimize( method = "minimize", params = {"maxnumlinesearch":10} )
#assert False

#epsilon     = 0.5
theta0 *=0
theta0 += 0.1
state  = State( theta0, state_params )

recorder = Recorder(record_stats=True)
Пример #5
0
mcmc_params["nbr_samples"] = nbr_samples
mcmc_params["xi"] = 0.1
mcmc_params["M"] = 100
mcmc_params["deltaS"] = 2
mcmc_params["max_nbr_tries"] = 10
mcmc_params["acquisition_model"] = AcquisitionModel(acquistion_params)

model = MH_Model(mcmc_params)

print "***************  RUNNING ABC REJECTION ***************"
lower_epsilon = -epsilon * 10
upper_epsilon = epsilon * 10

theta0 = problem.theta_prior_rand()
state = DiscState(theta0, state_params)
abc_recorder = Recorder(record_stats=True)
thetas, discs = abc_rejection(2, lower_epsilon, upper_epsilon, state,
                              problem.theta_prior_rand, abc_recorder)

initX = thetas.copy()
initY = abc_recorder.get_statistics()[:, 0].reshape((len(initX), 1))

pgp.add_data(initX, initY)
#gp.optimize( method = "minimize", params = {"maxnumlinesearch":10} )
#assert False

#epsilon     = 0.5
theta0 *= 0
theta0 += 0.1
state = State(theta0, state_params)