def run_experiment(path: Path, custom_settings: dict): # 1. Initialize the experiment exp = Experiment() exp.load_config(config_file=path / 'config.json', custom_settings=custom_settings) if exp.config['model']['n_areas'] == "TBD": exp.config['model']['n_areas'] = 2 # 2. Simulate contact areas sim = Simulation(experiment=exp) sim.run_simulation() # 3. Define MCMC mc = MCMC(data=sim, experiment=exp) # 4. Warm-up sampler and sample from posterior mc.warm_up() mc.sample() # 5. Evaluate ground truth mc.eval_ground_truth() # 6. Log sampling statistics and save samples to file mc.save_samples(run=0)
def run_experiment(experiment, data, run, initial_sample=None): mcmc = MCMC(data=data, experiment=experiment) mcmc.log_setup() # Sample mcmc.sample(initial_sample=initial_sample) # Save samples to file mcmc.log_statistics() mcmc.save_samples(run=run) # Use the last sample as the new initial sample return mcmc.samples['last_sample']
# 1. Initialize the experiment exp = Experiment() exp.load_config( config_file='experiments/simulation/sim_exp2/config.json', custom_settings={'model': { 'INHERITANCE': IN }}) exp.log_experiment() # 2. Simulate contact areas sim = Simulation(experiment=exp) sim.run_simulation() sim.log_simulation() # 3. Define MCMC mc = MCMC(data=sim, experiment=exp) mc.log_setup() # Rerun experiment to check for consistency for run in range(exp.config['mcmc']['N_RUNS']): # 4. Sample from posterior mc.warm_up() mc.sample() # 5. Evaluate ground truth mc.eval_ground_truth() # 6. Log sampling statistics and save samples to file mc.log_statistics() mc.save_samples(run=run)
dat = Data(experiment=exp) # Features dat.load_features() # Counts for priors dat.load_universal_counts() dat.load_inheritance_counts() # Log dat.log_loading() NUMBER_AREAS = range(1, 8) # Rerun experiment to check for consistency for run in range(exp.config['mcmc']['N_RUNS']): for N in NUMBER_AREAS: # Update config information according to the current setup exp.config['model']['N_AREAS'] = N # MCMC mc = MCMC(data=dat, experiment=exp) mc.log_setup() # Sample mc.warm_up() mc.sample() # Save samples to file mc.log_statistics() mc.save_samples(run=run)
def run_experiment(experiment, data, run): mcmc = MCMC(data=data, experiment=experiment) mcmc.log_setup() # Warm-up mcmc.warm_up() # Sample from posterior mcmc.sample() # Save samples to file mcmc.log_statistics() mcmc.save_samples(run=run) # Use the last sample as the new initial sample return mcmc.samples['last_sample']