#obs = np.recfromcsv('04012015_trimmed.csv',usecols=(1,4,14,32),delimiter=",")
#obs = obs[obs['koi_disposition'] != "FALSE POSITIVE"]
#obs.dtype.names = 'ktc_kepler_id','koi_disposition','period', 'T'

theta_0 = (2.0, 0.1, 9)
obs = model.generate_data(theta_0)

model.set_prior([stats.uniform(0, 90.0),
                 stats.uniform(0, 1),
                 stats.uniform(0, 20)])

model.set_data(obs)

start = time.time()
OT = simple_abc.pmc_abc(model, obs, epsilon_0=eps, min_particles=min_part,
                        steps=2, target_epsilon=eps, parallel=False)
out_pickle = file('pickles/kepler_pmc_xi_based_each_bin_dist_100_KNOWN_prime.pkl', 'w')
pickle.dump(OT, out_pickle)
out_pickle.close()

for i in range(0, steps):
    PT = OT
    OT = simple_abc.pmc_abc(model, obs, epsilon_0=eps, min_particles=min_part,
                        resume=PT, steps=2, target_epsilon=eps, parallel=False)
    out_pickle = file('pickles/kepler_pmc_xi_based_each_bin_dist_100_KNOW__{:}.pkl'.format(i),
                      'w')
    pickle.dump(OT, out_pickle)
    out_pickle.close()

end = time.time()
print 'Serial took {}s'.format(end - start)
model.set_data(obs)

start = time.time()

if known:
    PT = pickle.load(file(
                'RUNS/{0}/KNOWN/{0}_{1}samples_{2}.pkl'.format(name, min_part, 
                start_step), 'r'))
else:
    PT = pickle.load(file(
                'RUNS/{0}/SCIENCE/{0}_{1}samples_{2}.pkl'.format(name, min_part, 
                start_step),'r'))


OT = simple_abc.pmc_abc(model, obs, epsilon_0=1, min_samples=job_particles,
                    resume=PT, steps=1, parallel=False, n_procs=n_procs, 
                    sample_only=True)
if known:
    out_pickle = file(
        'RUNS/{0}/KNOWN/{0}_{1}_oversample{3}_{2}.pkl'.format(name, min_part, osamp_num, start_step+1),
        'w')
else:
    out_pickle = file(
        'RUNS/{0}/SCIENCE/{0}_{1}_oversamples{3}_{2}.pkl'.format(name, min_part, osamp_num, start_step+1),
        'w')

pickle.dump(OT, out_pickle)
out_pickle.close()

end = time.time()
print 'This run took {}s'.format(end - start)
                       'T', 'koi_prad')
    obs = obs[(obs['period'] >= 10.0) & (obs['period'] <= 320.0) &
                (obs['koi_prad'] <=20.0)]
    print obs[0:3]




model.set_prior([stats.uniform(0, 90.0),
                 stats.uniform(0, 1),
                 stats.uniform(0, 20)])

model.set_data(obs)

start = time.time()
OT = simple_abc.pmc_abc(model, obs, epsilon_0=eps, min_samples=min_part,
                        steps=1, parallel=True, n_procs=n_procs)
if known:
    out_pickle = file('RUNS/{0}/KNOWN/{0}_{1}samples_0.pkl'.format(name,
                                                                min_part), 'w')
    observed = file('RUNS/{0}/KNOWN/obs_data.pkl'.format(name), 'w')
    pickle.dump(obs, observed)
    observed.close()

else:
    out_pickle = file('RUNS/{0}/SCIENCE/{0}_{1}samples_0.pkl'.format(name,
                                                                min_part), 'w')
    observed = file('RUNS/{0}/SCIENCE/obs_data.pkl'.format(name), 'w')
    pickle.dump(obs, observed)
    observed.close()

pickle.dump(OT, out_pickle)
Exemple #4
0
eff = DetectionRamp(6, 16)

data = pop.observe(new=True, regr_trap=True).observe(eff)

model = ABCModel(pop, eff)
print("True model parameters {}: {}".format(model.params, model.theta_0))
model.null_distance_test(N=args.n_null)
print("norms = {}".format(model.distance_norms))

# model._distance_norms = np.array([ 1.        ,  4.49241213,  2.60025772,  2.73734061])

pmc_posterior = pmc_abc(
    model,
    data,
    epsilon_0=args.epsilon_0,
    min_samples=args.min_samples,
    steps=args.steps,
    verbose=True,
    parallel=True,
    n_procs=args.n_procs,
)

try:
    np.save(args.file, pmc_posterior)
except:
    logging.warning(
        "Posterior not saved to desired location "
        + "({}) because of problem!  Saved to recovered.npy".format(args.file)
    )
    np.save("recovered", pmc_posterior)