Created on 23 dec. 2010
Code author: jhkwakkel <j.h.kwakkel (at) tudelft (dot) nl>
Bases: object
ModelStructureInterface is one of the the two main classes used for performing EMA. This class should be extended to provide an interface to the actual model.
list of uncertainty instances
list of outcome instances
name of the model interface
results, this should be a dict with the names of the outcomes as key
interface to the model
Parameters: |
|
---|
Method called to initialize the model.
Parameters: |
|
---|
Note
This method should always be implemented. Although in simple cases, a simple pass can suffice.
Method for running an instantiated model structure.
This method should always be implemented.
Parameters: | case – keyword arguments for running the model. The case is a dict with the names of the uncertainties as key, and the values to which to set these uncertainties. |
---|
Note
This method should always be implemented.
Method for retrieving output after a model run.
Returns: | the results of a model run. |
---|
Method for reseting the model to its initial state. The default implementation only sets the outputs to an empty dict.
This model is called after finishing all the experiments, but just prior to returning the results. This method gives a hook for doing any cleanup, such as closing applications.
In case of running in parallel, this method is called during the cleanup of the pool, just prior to removing the temporary directories.
Method for retrieving model structure uncertainties.
Returns: | list of the uncertainties of the model interface. |
---|
Method for setting the working directory of the model interface. This method is used in case of running models in parallel. In this case, each worker process will have its own working directory, to avoid having to share files across processes. This requires the need to update the working directory to the new working directory.
Parameters: | wd – The new working directory. |
---|
Bases: object
One of the two main classes for performing EMA. The ensemble class is responsible for running experiments on one or more model structures across one or more policies, and returning the results.
The sampling is delegated to a sampler instance. The storing or results is delegated to a callback instance
the class has an attribute ‘parallel’ that specifies whether the experiments are to be run in parallel or not. By default, ‘parallel’ is False.
an illustration of use
>>> model = UserSpecifiedModelInterface(r'working directory', 'name')
>>> ensemble = SimpleModelEnsemble()
>>> ensemble.set_model_structure(model)
>>> ensemble.parallel = True #parallel processing is turned on
>>> results = ensemble.perform_experiments(1000) #perform 1000 experiments
In this example, a 1000 experiments will be carried out in parallel on the user specified model interface. The uncertainties are retrieved from model.uncertainties and the outcomes are assumed to be specified in model.outcomes.
Class responsible for running experiments on diverse model structures and storing the results.
Parameters: | sampler – the sampler to be used for generating experiments. By default, the sampling technique is LHSSampler. |
---|
Method responsible for running the experiments on a structure. In case of multiple model structures, the outcomes are set to the intersection of the sets of outcomes of the various models.
Parameters: |
|
---|---|
Returns: | a structured numpy array containing the experiments, and a dict with the names of the outcomes as keys and an numpy array as value. |
suggested use
In general, analysis scripts require both the structured array of the experiments and the dictionary of arrays containing the results. The recommended use is the following:
>>> results = ensemble.perform_experiments(10000) #recommended use
>>> experiments, output = ensemble.perform_experiments(10000) #will work fine
The latter option will work fine, but most analysis scripts require to wrap it up into a tuple again:
>>> data = (experiments, output)
Another reason for the recommended use is that you can save this tuple directly:
>>> import expWorkbench.util as util
>>> util.save_results(results, file)
Add a policy.
Parameters: | policy – policy to be added, policy should be a dict with at least a name. |
---|
Add policies, policies should be a collection of policies.
Parameters: | policies – policies to be added, every policy should be a dict with at least a name. |
---|
Set the model structure. This function wraps the model structure in a tuple, limiting the number of model structures to 1.
Parameters: | modelStructure – a ModelStructureInterface instance. |
---|
Add a model structure to the list of model structures.
Parameters: | ms – a ModelStructureInterface instance. |
---|
add a collection of model structures to the list of model structures.
Parameters: | mss – a collection of ModelStructureInterface instances |
---|
number of cases specifies the number of cases to generate in case of Monte Carlo and Latin Hypercube sampling.
In case of full factorial sampling it specifies the resolution on non categorical uncertainties.
In case of multiple model structures, the uncertainties over which to explore is the intersection of the sets of uncertainties of the model interface instances.
Parameters: | nrOfCases – In case of Latin Hypercube sampling and Monte Carlo sampling, nrOfCases specifies the number of cases to generate. In case of Full Factorial sampling, nrOfCases specifies the resolution to use for sampling continuous uncertainties. |
---|