Stochastic Model#
- class rocketpy.stochastic.StochasticModel[source]#
Base class for all Stochastic classes. This class validates input arguments, saves them as attributes, and generates a dictionary with randomly generated input arguments.
See also
Notes
Please notice that the methods starting with an underscore are not meant to be called directly by the user. These methods may receive breaking changes without notice, so use them at your own risk.
- __init__(obj, seed=None, **kwargs)[source]#
Initialize the StochasticModel class with validated input arguments.
- Parameters:
obj (
object) – The main object of the class.seed (
int, optional) – Seed for the random number generator. The default is None so that a newnumpy.random.Generatorobject is created.**kwargs (
dict) – Dictionary of input arguments for the class. Valid argument types include tuples, lists, ints, floats, or None. Arguments will be validated and saved as class attributes in a specific format, which is described in the “Working with Stochastic Models” page.
- Raises:
AssertionError – If the input arguments do not conform to the specified formats.
- _set_stochastic(seed=None)[source]#
Set the stochastic attributes from the input dictionary. This method is useful to reset or reseed the attributes of the instance.
- Parameters:
seed (
int, optional) – Seed for the random number generator.
- _validate_tuple(input_name, input_value, getattr=<built-in function getattr>)[source]#
Validate tuple arguments.
- Parameters:
input_name (
str) – Name of the input argument.input_value (
tuple) – Value of the input argument. This is the tuple to be validated.getattr (
function) – Function used to get the attribute value from the object.
- Returns:
Validated tuple in the format (nominal value, standard deviation, distribution function).
- Return type:
tuple- Raises:
AssertionError – If the input is not in a valid format.
- _validate_tuple_length_two(input_name, input_value, getattr=<built-in function getattr>)[source]#
Validate tuples with length 2.
- Parameters:
input_name (
str) – Name of the input argument.input_value (
tuple) – Value of the input argument.getattr (
function) – Function to get the attribute value from the object.
- Returns:
Validated tuple in the format (nominal value, standard deviation, distribution function).
- Return type:
tuple- Raises:
AssertionError – If the input is not in a valid format.
- _validate_tuple_length_three(input_name, input_value, getattr=<built-in function getattr>)[source]#
Validate tuples with length 3.
- Parameters:
input_name (
str) – Name of the input argument.input_value (
tuple) – Value of the input argument.getattr (
function) – Function to get the attribute value from the object.
- Returns:
Validated tuple in the format (nominal value, standard deviation, distribution function).
- Return type:
tuple- Raises:
AssertionError – If the input is not in a valid format.
- _validate_list(input_name, input_value, getattr=<built-in function getattr>)[source]#
Validate list arguments.
- Parameters:
input_name (
str) – Name of the input argument.input_value (
list) – Value of the input argument.getattr (
function) – Function to get the attribute value from the object.
- Returns:
Validated list.
- Return type:
list- Raises:
AssertionError – If the input is not in a valid format.
- _validate_scalar(input_name, input_value, getattr=<built-in function getattr>)[source]#
Validate scalar arguments. If the input is a scalar, the nominal value will be taken from the object passed, and the standard deviation will be the scalar value. The distribution function will be set to “normal”.
- Parameters:
input_name (
str) – Name of the input argument.input_value (
float) – Value of the input argument.getattr (
function) – Function to get the attribute value from the object.
- Returns:
Validated tuple in the format (nominal value, standard deviation, distribution function).
- Return type:
tuple
- _validate_factors(input_name, input_value, seed)[source]#
Validate factor arguments.
- Parameters:
input_name (
str) – Name of the input argument.input_value (
tupleorlist) – Value of the input argument.
- Returns:
Validated tuple or list.
- Return type:
tupleorlist- Raises:
AssertionError – If the input is not in a valid format.
- _validate_tuple_factor(input_name, factor_tuple)[source]#
Validate tuple factors.
- Parameters:
input_name (
str) – Name of the input argument.factor_tuple (
tuple) – Value of the input argument.
- Returns:
Validated tuple.
- Return type:
tuple- Raises:
AssertionError – If the input is not in a valid format.
- _validate_list_factor(input_name, factor_list)[source]#
Validate list factors.
- Parameters:
input_name (
str) – Name of the input argument.factor_list (
list) – Value of the input argument.
- Returns:
Validated list.
- Return type:
list- Raises:
AssertionError – If the input is not in a valid format.
- _validate_1d_array_like(input_name, input_value)[source]#
Validate 1D array-like arguments.
- Parameters:
input_name (
str) – Name of the input argument.input_value (
list) – Value of the input argument.
- Raises:
AssertionError – If the input is not in a valid format.
- _validate_positive_int_list(input_name, input_value)[source]#
Validate lists of positive integers.
- Parameters:
input_name (
str) – Name of the input argument.input_value (
list) – Value of the input argument.
- Raises:
AssertionError – If the input is not in a valid format.
- _validate_custom_sampler(input_name, sampler, seed=None)[source]#
Validate a custom sampler.
- Parameters:
input_name (
str) – Name of the input argument.sampler (
CustomSampler object) – Custom sampler provided by the userseed (
int, optional) – Seed for the random number generator. The default is None
- Raises:
AssertionError – If the input is not in a valid format.
- _validate_airfoil(airfoil)[source]#
Validate airfoil input.
- Parameters:
airfoil (
list[tuple]) – List of tuples with two items.- Raises:
AssertionError – If the input is not in a valid format.
- dict_generator()[source]#
Generate a dictionary with randomly generated input arguments. The last generated dictionary is saved as a class attribute called last_rnd_dict.
- Yields:
dict– Dictionary with the randomly generated input arguments.
Notes
- The dictionary is generated by iterating over the class attributes and:
If the attribute is a tuple, the value is generated using the distribution function specified in the tuple.
If the attribute is a list, the value is randomly chosen from the list.