src.blocks.Scenarios module
This module is responsible for the generation of test scenarios.
It includes one class for the scenario generation. See details in its own documentation.
Contact person: Stefan Riedmaier Creation date: 20.04.2020 Python version: 3.8
- class src.blocks.Scenarios.Scenarios(config, domain, instance)
Bases:
objectThis class is responsible for the generation of test scenarios.
It includes a main method called “generate_scenarios” that runs through the generation process by calling the other methods. See more details in the documentation of the generate_scenarios method.
- generate_aleatory_samples(number_samples)
This function generates the samples for the aleatory parameters.
It offers several options: - mcs: Monte Carlo sampling, either from uniform or gaussian distributions - lhs: Latin Hypercube sampling, from uniform distributions
- Parameters:
number_samples (int) – number of aleatory parameter samples
- generate_epistemic_samples()
This function generates the samples for the epistemic parameters.
It offers several options: 1) In the repetitions case (3D), Monte Carlo sampling from uniform distributions is available. 2) In the non-deterministic case (4D), the following options are available: - mcs: Monte Carlo sampling, from uniform distributions - lhs: Latin Hypercube sampling, from uniform distributions - full_factorial_doe: full factorial design of experiments with all permutations
- generate_scenarios(executed_scenarios_da=<xarray.DataArray ()> array(None, dtype=object), executed_space_scenarios_da=<xarray.DataArray ()> array(None, dtype=object))
This function generates an array of test scenarios, possibly with repetitions or epistemic and aleatory samples.
The generation process consists of the following steps: 1) In the first step, the samples in the scenario space are generated and returned later (space scenarios). There are two options: a) generate_space_samples: creates the space scenarios from scratch; b) process_executed_scenarios: uses already executed scenarios with regard to a re-simulation. 2) In the second step, epistemic and aleatory samples can be added in case of non-deterministic simulations to get the final scenario array. The methods generate_epistemic_samples, generate_aleatory_samples and reshape_sample_array are responsible for this. In case of multiple experimental repetitions, the epistemic and aleatory samples are independent of each other. In case of nested uncertainty propagation, the epistemic samples will be combined with the aleatory samples, respectively. In the deterministic case, the final scenario array is identical to the space scenarios. 3) Finally, scenario_csv_handler.save is used to store the scenarios in a csv file for archiving and re-loading.
The scenarios are stored in xarrays, recognizable by the “_da”-endings of the variables. The order of the parameters is the same as defined in the config file. The space scenarios are always two-dimensional arrays: ‘space_samples’, ‘parameters’ (2D) The final scenarios might have different dimensions depending on the selected case: - ‘space_samples’, ‘parameters’ (2D): deterministic simulation - ‘space_samples’, ‘repetitions’, ‘parameters’ (3D): experiment with multiple repetitions - ‘space_samples’, ‘epistemic_samples’, ‘aleatory_samples’, ‘parameters’ (4D): nested uncerainty propagation (or just with either epistemic or aleatory samples)
The exact shape depends on the doe method, the number of samples, etc.
Example: - Assuming 5 space parameters with 3-3-2-2-2 full factorial samples, results in 72 space samples. - Assuming 2 epistemic parameters with 4-3 full factorial samples, results in 12 epistemic samples. - Assuming 3 aleatory parameters with 100 monte carlo samples, results in 100 aleatory samples. -> Thus, the 4d array has a dimension of 72x12x100x5. It consists of 86.400 samples and 5 space parameters.
The values vary starting at the last column backwards: - Thus, for the first space and first epistemic sample, all aleatory samples are generated. - Then, for the first space sample, the second epistemic sample is generated and again all aleatory samples. - … - Then, for the first space sample, the last epistemic sample is generated and again all aleatory samples. - Then, for the second space sample, the first epistemic sample is generated and again all aleatory samples. - … - Finally, for the last space sample, the last epistemic sample is generated and again all aleatory samples.
- Parameters:
executed_scenarios_da (xr.DataArray) – (optional) executed scenarios for a re-simulation
executed_space_scenarios_da (xr.DataArray) – (optional) idealized space scenarios for a re-simulation
- Returns:
array of all space, epistemic and aleatory samples and array of ideal space samples
- Return type:
tuple(xr.DataArray, xr.DataArray)
- generate_space_samples()
This function generates the samples for the scenario space parameters from scratch.
It offers several options: - mcs: Monte Carlo sampling, either from uniform or gaussian distributions - lhs: Latin Hypercube sampling, from uniform distributions - full_factorial_doe: full factorial design of experiments with all permutations - manual: manually specified scenarios - read_csv: re-loading scenarios from a csv file - post: skipping the scenario generation and extracting them later in a data-driven assessment / post-processing
- process_executed_scenarios(executed_scenarios_da, executed_space_scenarios_da)
This function processes executed scenarios, typically from an experiment for a re-simulation.
It offers different options: 1) The scenarios can be reloaded from a csv file. 2) In the deterministic case (2D), the scenarios are used as they are. 3) In the repetitions case (3D), the scenarios can be - used as they are. - averaged. - used to extract the space samples. 4) In the non-deterministic case (4D), the scenarios are used as they are.
- Parameters:
executed_scenarios_da (xr.DataArray) – scenarios already executed in advance
executed_space_scenarios_da (xr.DataArray) – corresponding ideal space scenarios
- reshape_sample_array()
This function reshapes a large two-dimensional sample array to reflect possible epistemic and aleatory loops.
It outputs a 3d array in case of - typically experimental - repetitions in a single loop. It outputs a 4d array in case of nested two loop sampling with epistemic and aleatory parameters.