cosapp.drivers.montecarlo¶
Classes
|
This driver execute a MonteCarlo simulation on its system. |
|
Class representing a random variable in a system of interest |
- class cosapp.drivers.montecarlo.MonteCarlo(name: str, owner: System | None = None, **options)[source]¶
Bases:
AbstractSetOfCasesThis driver execute a MonteCarlo simulation on its system.
- A: numpy.ndarray¶
- X0: numpy.ndarray¶
- Y0: numpy.ndarray¶
- add_random_variable(name, distribution: Distribution | None = None) None[source]¶
- add_random_variable(specs: dict[str, Distribution], /) None
- add_random_variable(varname: str, distribution: Distribution | None = None) None
- add_random_variable(varnames: Iterable[str], distribution: Distribution | None = None) None
Add variable to be randomly perturbated, following an optional distribution.
The perturbation distribution is defined by the variable distribution details.
- Parameters:
varname (Union[str, Iterable[str], dict[str, Distribution]]) – Name of the variable to be perturbed, or iterable thereof. If the argument is a dict, it is interpreted as a {name: distribution} specification
distribution (cosapp.utils.distributions.Distribution | None) – Distribution of the variable(s) to be perturbed. If None (default), distributions are deduced from variable names. This argument is only meaningful when a variable name or a list thereof is provided.
Examples
>>> from cosapp.utils.distributions import Normal, Uniform >>> >>> montecarlo = system.add_driver(MonteCarlo("montecarlo")) >>> >>> montecarlo.add_random_variable("port.v") >>> montecarlo.add_random_variable("port.v", Normal(...)) >>> >>> montecarlo.add_random_variable(["x", "port.v"]) >>> montecarlo.add_random_variable(["x", "port.v"], Normal(...)) >>> >>> montecarlo.add_random_variable({ >>> "x": Normal(...), >>> "port.v": Uniform(...), >>> })
- add_response(name: str | Iterable[str]) None[source]¶
Add a variable for which the statistical response will be calculated.
- Parameters:
name (Union[str, Iterable[str]]) – List of variable names to add
- draws¶
- linear¶
- perturbations¶
- random_variable_data() dict[str, Distribution][source]¶
Builds and returns the dictionary associating distributions to random variable names
- property random_variable_names: Iterator[str]¶
Generator yielding all random variable names
- property random_variables: Iterator[RandomVariable]¶
Generator yielding all random variable names
- reference_case_solution: dict[str, float]¶
- response_varnames: list[str]¶
- class cosapp.drivers.montecarlo.RandomVariable(system: System, varname: str, distribution: Distribution | None = None)[source]¶
Bases:
objectClass representing a random variable in a system of interest
- connector: SystemConnector | None¶
- distribution: Distribution | None¶
- name¶
- property value¶