How to use the easyvvuq.collate function in easyvvuq

To help you get started, we’ve selected a few easyvvuq examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github UCL-CCS / EasyVVUQ / tests / test_gauss.py View on Github external
number_of_samples = 3
    number_of_replicas = 5

    # Create an encoder and decoder for the gauss app
    encoder = uq.encoders.GenericEncoder(template_fname='tests/gauss/gauss.template',
                                         target_filename='gauss_in.json')
    decoder = GaussDecoder(target_filename=params['out_file']['default'])

    my_campaign.add_app(name="gauss",
                        params=params,
                        encoder=encoder,
                        decoder=decoder
                        )

    # Create a collation element for this campaign
    collater = uq.collate.AggregateSamples(average=False)
    my_campaign.set_collater(collater)

    # Make a random sampler
    vary = {
        "mu": cp.Uniform(1.0, 100.0),
    }
    sampler1 = uq.sampling.RandomSampler(vary=vary)

    # Set the campaign to use this sampler
    my_campaign.set_sampler(sampler1)

    # Draw samples
    my_campaign.draw_samples(num_samples=number_of_samples,
                             replicas=number_of_replicas)

    # TODO: Assert no. samples in db = number_of_samples*number_of_replicas
github UCL-CCS / EasyVVUQ / test / test_cannonsim.py View on Github external
my_campaign = uq.Campaign(state_filename="test_input/test_cannonsim.json")

# Specify which parameters can vary, and their (prior) distributions.
my_campaign.vary_param("angle",    dist=uq.distributions.uniform(0.0, 1.0))
my_campaign.vary_param("velocity", dist=uq.distributions.normal(10.0, 1.0))
my_campaign.vary_param("mass",     dist=uq.distributions.custom_histogram("test_input/mass_distribution.csv"))

# Apply the randomSampler UQP, generating 15 runs
uq.uqp.sampling.random_sampler(my_campaign, num_samples=15)

# Execute and analyse
my_campaign.populate_runs_dir()
my_campaign.apply_for_each_run(uq.execute_local)

# Aggregate results from all runs
uq.collate.aggregate_samples(my_campaign)

# Apply ensemble bootstrap UQP
stats = uq.uqp.analysis.BasicStats(my_campaign)
results, output_file = stats.run_analysis()

# Output
print(my_campaign)
my_campaign.save_state("out_cannonsim.json")
github UCL-CCS / EasyVVUQ / tests / test_aggregate_by_variable.py View on Github external
"velocity": {
            "type": "float",
            "min": 0.0,
            "max": 1000.0,
            "default": 10.0}}

    # Create an encoder and decoder for the cannonsim app
    encoder = uq.encoders.GenericEncoder(
        template_fname='tests/cannonsim/test_input/cannonsim.template',
        delimiter='#',
        target_filename='in.cannon')
    output_cols = ['Dist', 'lastvx', 'lastvy']
    decoder = uq.decoders.SimpleCSV(
        target_filename='output.csv', output_columns=output_cols, header=0)
    # Create a collation element for this campaign
    collater = uq.collate.AggregateByVariables(average=False)
    # Make a random sampler
    sweep = {
        "angle": [0.1, 0.2, 0.3],
        "height": [2.0, 10.0],
        "velocity": [10.0, 10.1, 10.2]
    }
    sampler = uq.sampling.BasicSweep(sweep=sweep)

    my_campaign = uq.Campaign(name='aggregate_by_var', work_dir=tmpdir, db_location='sqlite:///')
    my_campaign.add_app(name="cannon_test",
                        params=params,
                        encoder=encoder,
                        decoder=decoder,
                        collater=collater)
    my_campaign.set_app("cannon_test")
    sampler = uq.sampling.BasicSweep(sweep=sweep)
github UCL-CCS / EasyVVUQ / test / test_gauss.py View on Github external
"""
__license__ = "LGPL"


my_campaign = uq.Campaign(state_filename="test_input/test_gauss.json")

my_campaign.vary_param("mu", dist=uq.distributions.uniform(1.0, 100.0))
uq.uqp.sampling.random_sampler(my_campaign, num_samples=2)
uq.uqp.sampling.add_replicas(my_campaign, replicates=5)

my_campaign.populate_runs_dir()

my_campaign.apply_for_each_run(uq.execute_local)

# Aggregate results from all runs (averaging values for each run)
uq.collate.aggregate_samples(my_campaign, average=True)

# Apply ensemble bootstrap UQP
ensemble_boot = uq.uqp.analysis.EnsembleBoot(my_campaign)
results, output_file = ensemble_boot.run_analysis()

print(my_campaign)
my_campaign.save_state("out_gauss.json")
github UCL-CCS / EasyVVUQ / tests / test_sweep_sampler.py View on Github external
decoder = uq.decoders.SimpleCSV(
        target_filename='output.csv', output_columns=[
            'Dist', 'lastvx', 'lastvy'], header=0)

    # Add the cannonsim app
    my_campaign.add_app(name="cannonsim",
                        params=params,
                        encoder=encoder,
                        decoder=decoder)

    # Set the active app to be cannonsim (this is redundant when only one app
    # has been added)
    my_campaign.set_app("cannonsim")

    # Create a collation element for this campaign
    collater = uq.collate.AggregateSamples(average=False)
    my_campaign.set_collater(collater)

    # Make a sweep sampler
    sweep = {
        "angle": [0.1, 0.2, 0.3],
        "height": [2.0, 10.0],
        "velocity": [10.0, 10.1, 10.2]
    }
    sampler1 = uq.sampling.BasicSweep(sweep=sweep)

    print("Serialized sampler:", sampler1.serialize())

    # Set the campaign to use this sampler
    my_campaign.set_sampler(sampler1)

    # Draw first 5 samples
github UCL-CCS / EasyVVUQ / tests / test_jinja_encoder.py View on Github external
# "Nh": cp.DiscreteUniform(10, 20),
        # "extent": cp.Uniform(1000, 2000),
        "seed": cp.Uniform(1, 2000),
    }

    output_columns = ['cfrac', 'lwp', 'rwp', 'zb', 'zi', 'prec', 'wq', 'wtheta', 'we', 'walltime']
    my_sampler = uq.sampling.SCSampler(vary=vary, polynomial_order=2,
                                       quadrature_rule="C")
    my_campaign = uq.Campaign(name='dales', work_dir=tmpdir, db_location='sqlite:///')
    encoder = JinjaEncoder(template_fname='tests/jinjaencoder/namoptions.template',
                           target_filename='namoptions.001')
    decoder = uq.decoders.SimpleCSV(
        target_filename='results.csv',
        output_columns=output_columns,
        header=0)
    collater = uq.collate.AggregateSamples(average=False)
    my_campaign.add_app(name="dales",
                        params=params,
                        encoder=encoder,
                        decoder=decoder,
                        collater=collater)
    my_campaign.verify_all_runs = False  # to prevent errors on integer quantities
    my_campaign.set_sampler(my_sampler)
    my_campaign.draw_samples()
    my_campaign.populate_runs_dir()
github UCL-CCS / EasyVVUQ / docs / tutorial_files / easyvvuq_pce_tutorial.py View on Github external
delimiter='$',
    target_filename='cooling_in.json')

decoder = uq.decoders.SimpleCSV(target_filename="output.csv",
                                output_columns=["te", "ti"],
                                header=0)

# Add the app (automatically set as current app)
my_campaign.add_app(name="cooling",
                    params=params,
                    encoder=encoder,
                    decoder=decoder
                    )

# Create a collation element for this campaign
collater = uq.collate.AggregateSamples(average=False)
my_campaign.set_collater(collater)

# Create the sampler
vary = {
    "kappa": cp.Uniform(0.025, 0.075),
    "t_env": cp.Uniform(15, 25)
}
my_sampler = uq.sampling.PCESampler(vary=vary,
                                    polynomial_order=3)

# Associate the sampler with the campaign
my_campaign.set_sampler(my_sampler)

# Will draw all (of the finite set of samples)
my_campaign.draw_samples()
github UCL-CCS / EasyVVUQ / docs / tutorial_files / easyvvuq_gauss_tutorial.py View on Github external
"default": "output.csv"
    }
}

# 3. Wrap Application
#    - Define a new application (we'll call it 'gauss'), and the encoding/decoding elements it needs
#    - Also requires a collation element - his will be responsible for aggregating the results
encoder = uq.encoders.GenericEncoder(template_fname=template,
                                     target_filename=input_filename)

decoder = uq.decoders.SimpleCSV(
            target_filename=out_file,
            output_columns=['Step', 'Value'],
            header=0)

collater = uq.collate.AggregateSamples(average=True)

my_campaign.add_app(name="gauss",
                    params=params,
                    encoder=encoder,
                    decoder=decoder,
                    collater=collater
                    )

# 4. Specify Sampler
#    -  vary the `mu` parameter only
vary = {
    "mu": cp.Uniform(1.0, 100.0),
}

my_sampler = uq.sampling.RandomSampler(vary=vary)
github UCL-CCS / EasyVVUQ / docs / tutorial_files / easyvvuq_gp.py View on Github external
"kappa": {"type": "float", "min": 0.0, "max": 0.1, "default": 0.025},
    "t_env": {"type": "float", "min": 0.0, "max": 40.0, "default": 15.0},
    "out_file": {"type": "string", "default": "output.csv"}
}

# Create an encoder, decoder and collater for PCE test app
encoder = uq.encoders.GenericEncoder(
    template_fname='cooling.template',
    delimiter='$',
    target_filename='cooling_in.json')

decoder = uq.decoders.SimpleCSV(target_filename="output.csv",
                                output_columns=["te"],
                                header=0)

collater = uq.collate.AggregateSamples(average=False)

# Add the app (automatically set as current app)
my_campaign.add_app(name="cooling",
                    params=params,
                    encoder=encoder,
                    decoder=decoder,
                    collater=collater)

# Create the sampler
vary = {
    "kappa": cp.Uniform(0.025, 0.075),
    "t_env": cp.Uniform(15, 25)
}
my_sampler = uq.sampling.quasirandom.LHCSampler(vary)

# Associate the sampler with the campaign
github UCL-CCS / EasyVVUQ / docs / tutorial_files / easyvvuq_dask_tutorial.py View on Github external
"temp_init": {"type": "float", "min": 0.0, "max": 100.0, "default": 95.0},
        "kappa": {"type": "float", "min": 0.0, "max": 0.1, "default": 0.025},
        "t_env": {"type": "float", "min": 0.0, "max": 40.0, "default": 15.0},
        "out_file": {"type": "string", "default": "output.csv"}
    }
    # Create an encoder, decoder and collater for PCE test app
    encoder = uq.encoders.GenericEncoder(
        template_fname='cooling.template',
        delimiter='$',
        target_filename='cooling_in.json')

    decoder = uq.decoders.SimpleCSV(target_filename="output.csv",
                                    output_columns=["te"],
                                    header=0)

    collater = uq.collate.AggregateSamples(average=False)

    # Add the app (automatically set as current app)
    my_campaign.add_app(name="cooling",
                        params=params,
                        encoder=encoder,
                        decoder=decoder,
                        collater=collater)

    # Create the sampler
    vary = {
        "kappa": cp.Uniform(0.025, 0.075),
        "t_env": cp.Uniform(15, 25)
    }
    my_sampler = uq.sampling.PCESampler(vary=vary,
                                        polynomial_order=3)