Beispiel #1
0
    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)
Beispiel #2
0
    for S in SETUP:

        # Update config information according to the current setup
        custom_settings = {
            'simulation': {
                'i_contact': I_CONTACT[S[0]],
                'e_contact': E_CONTACT[S[0]],
                'STRENGTH': S[0],
                'area': S[1]
            }
        }

        # 1. Initialize the experiment
        exp = Experiment()
        exp.load_config(
            config_file='experiments/simulation/sim_exp1/config.json',
            custom_settings=custom_settings)
        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']):
Beispiel #3
0
from sbayes.experiment_setup import Experiment
from sbayes.simulation import Simulation
from sbayes.mcmc_setup import MCMC

if __name__ == '__main__':

    # When performing the MCMC iterate over different setups (inheritance)
    INHERITANCE = [False, True]

    for IN in INHERITANCE:
        # 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']):
Beispiel #4
0
from sbayes.experiment_setup import Experiment
from sbayes.simulation import Simulation
from sbayes.mcmc_setup import MCMC

if __name__ == '__main__':
    import os

    # 1. Initialize the experiment
    exp = Experiment()
    exp.load_config(config_file='experiments/simulation/sim_exp3/config.json')
    exp.log_experiment()

    # 2. Simulate contact areas
    sim = Simulation(experiment=exp)
    sim.run_simulation()
    sim.log_simulation()

    # Iterate over different setups (different number of areas)
    NUMBER_AREAS = range(1, 8)

    for N in NUMBER_AREAS:
        # Update config information according to the current setup
        exp.config['model']['n_areas'] = N

        # 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']):
Beispiel #5
0
from sbayes.experiment_setup import Experiment
from sbayes.load_data import Data
from sbayes.mcmc_setup import MCMC

if __name__ == '__main__':

    # Initialize the experiment
    exp = Experiment()
    exp.load_config(config_file='experiments/south_america/config.json')
    exp.log_experiment()

    # Load Data
    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
Beispiel #6
0
from sbayes.experiment_setup import Experiment
from sbayes.load_data import Data
from sbayes.mcmc_setup import MCMC

if __name__ == '__main__':

    # Initialize the experiment
    exp = Experiment()
    exp.load_config(config_file='experiments/balkan/config.json')
    exp.log_experiment()

    # Load Data
    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
Beispiel #7
0
from sbayes.experiment_setup import Experiment
from sbayes.simulation import Simulation
from sbayes.mcmc_setup import MCMC

if __name__ == '__main__':

    # When performing the MCMC iterate over different setups (inheritance)
    INHERITANCE = [False, True]

    for IN in INHERITANCE:
        # 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']):
Beispiel #8
0
    N_BACKGROUND = 20
    N_AREA = 10

    # Spatial distribution
    BBOX = Rectangle(left=0, bottom=0, right=100, top=100)
    AREA_MEAN = np.array([35, 60])
    AREA_STD = 10

    # Generate spatial locations
    background_locations = generate_background_locations(N_BACKGROUND, BBOX)
    area_locations = generate_area_locations(N_AREA, AREA_MEAN, AREA_STD)
    plot_locations(background_locations, area_locations)

    # 1. Initialize the experiment
    exp = Experiment()
    exp.load_config(config_file='../config.json')
    exp.log_experiment()

    # When simulating iterate over different setups (different areas and strengths of contact)
    I_CONTACT = [1.5, 2, 2.5]
    E_CONTACT = [1.25, 0.75, 0.25]
    STRENGTH = range(len(E_CONTACT))
    AREA = [4, 6, 3, 8]
    SETUP = list(itertools.product(STRENGTH, AREA))

    for S in SETUP:

        # Update config information according to the current setup
        exp.config['simulation']['I_CONTACT'] = I_CONTACT[S[0]]
        exp.config['simulation']['E_CONTACT'] = E_CONTACT[S[0]]
        exp.config['simulation']['STRENGTH'] = S[0]