ishigami_space module¶
The uncertain space used in the Ishigami use case.
- class gemseo.problems.uncertainty.ishigami.ishigami_space.IshigamiSpace(uniform_distribution_name=UniformDistribution.SCIPY)[source]¶
Bases:
ParameterSpace
The uncertain space used in the Ishigami use case.
\(X_1,X_2,X_3\) are independent random variables uniformly distributed between \(-\pi\) and \(\pi\).
This uncertain space uses the class
SPUniformDistribution
.See [IH90].
- Parameters:
uniform_distribution_name (UniformDistribution) –
The name of the class implementing the uniform distribution.
By default it is set to “SPUniformDistribution”.
- class DesignVariable(size=1, var_type=_DesignVariableType.FLOAT, l_b=None, u_b=None, value=None)¶
Bases:
NamedTuple
A design variable.
Create new instance of DesignVariable(size, var_type, l_b, u_b, value)
- Parameters:
size (int | None) –
By default it is set to 1.
var_type (NDArray[_DesignVariableType] | _DesignVariableType | None) –
By default it is set to “float”.
l_b (ndarray | None)
u_b (ndarray | None)
value (ndarray | None)
- count(value, /)¶
Return number of occurrences of value.
- index(value, start=0, stop=9223372036854775807, /)¶
Return first index of value.
Raises ValueError if the value is not present.
- DesignVariableType¶
alias of
_DesignVariableType
- class UniformDistribution(value)[source]¶
Bases:
StrEnum
The name of the class implementing the uniform distribution.
- capitalize()¶
Return a capitalized version of the string.
More specifically, make the first character have upper case and the rest lower case.
- casefold()¶
Return a version of the string suitable for caseless comparisons.
- center(width, fillchar=' ', /)¶
Return a centered string of length width.
Padding is done using the specified fill character (default is a space).
- count(sub[, start[, end]]) int ¶
Return the number of non-overlapping occurrences of substring sub in string S[start:end]. Optional arguments start and end are interpreted as in slice notation.
- encode(encoding='utf-8', errors='strict')¶
Encode the string using the codec registered for encoding.
- encoding
The encoding in which to encode the string.
- errors
The error handling scheme to use for encoding errors. The default is ‘strict’ meaning that encoding errors raise a UnicodeEncodeError. Other possible values are ‘ignore’, ‘replace’ and ‘xmlcharrefreplace’ as well as any other name registered with codecs.register_error that can handle UnicodeEncodeErrors.
- endswith(suffix[, start[, end]]) bool ¶
Return True if S ends with the specified suffix, False otherwise. With optional start, test S beginning at that position. With optional end, stop comparing S at that position. suffix can also be a tuple of strings to try.
- expandtabs(tabsize=8)¶
Return a copy where all tab characters are expanded using spaces.
If tabsize is not given, a tab size of 8 characters is assumed.
- find(sub[, start[, end]]) int ¶
Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation.
Return -1 on failure.
- format(*args, **kwargs) str ¶
Return a formatted version of S, using substitutions from args and kwargs. The substitutions are identified by braces (‘{’ and ‘}’).
- format_map(mapping) str ¶
Return a formatted version of S, using substitutions from mapping. The substitutions are identified by braces (‘{’ and ‘}’).
- index(sub[, start[, end]]) int ¶
Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation.
Raises ValueError when the substring is not found.
- isalnum()¶
Return True if the string is an alpha-numeric string, False otherwise.
A string is alpha-numeric if all characters in the string are alpha-numeric and there is at least one character in the string.
- isalpha()¶
Return True if the string is an alphabetic string, False otherwise.
A string is alphabetic if all characters in the string are alphabetic and there is at least one character in the string.
- isascii()¶
Return True if all characters in the string are ASCII, False otherwise.
ASCII characters have code points in the range U+0000-U+007F. Empty string is ASCII too.
- isdecimal()¶
Return True if the string is a decimal string, False otherwise.
A string is a decimal string if all characters in the string are decimal and there is at least one character in the string.
- isdigit()¶
Return True if the string is a digit string, False otherwise.
A string is a digit string if all characters in the string are digits and there is at least one character in the string.
- isidentifier()¶
Return True if the string is a valid Python identifier, False otherwise.
Call keyword.iskeyword(s) to test whether string s is a reserved identifier, such as “def” or “class”.
- islower()¶
Return True if the string is a lowercase string, False otherwise.
A string is lowercase if all cased characters in the string are lowercase and there is at least one cased character in the string.
- isnumeric()¶
Return True if the string is a numeric string, False otherwise.
A string is numeric if all characters in the string are numeric and there is at least one character in the string.
- isprintable()¶
Return True if the string is printable, False otherwise.
A string is printable if all of its characters are considered printable in repr() or if it is empty.
- isspace()¶
Return True if the string is a whitespace string, False otherwise.
A string is whitespace if all characters in the string are whitespace and there is at least one character in the string.
- istitle()¶
Return True if the string is a title-cased string, False otherwise.
In a title-cased string, upper- and title-case characters may only follow uncased characters and lowercase characters only cased ones.
- isupper()¶
Return True if the string is an uppercase string, False otherwise.
A string is uppercase if all cased characters in the string are uppercase and there is at least one cased character in the string.
- join(iterable, /)¶
Concatenate any number of strings.
The string whose method is called is inserted in between each given string. The result is returned as a new string.
Example: ‘.’.join([‘ab’, ‘pq’, ‘rs’]) -> ‘ab.pq.rs’
- ljust(width, fillchar=' ', /)¶
Return a left-justified string of length width.
Padding is done using the specified fill character (default is a space).
- lower()¶
Return a copy of the string converted to lowercase.
- lstrip(chars=None, /)¶
Return a copy of the string with leading whitespace removed.
If chars is given and not None, remove characters in chars instead.
- static maketrans()¶
Return a translation table usable for str.translate().
If there is only one argument, it must be a dictionary mapping Unicode ordinals (integers) or characters to Unicode ordinals, strings or None. Character keys will be then converted to ordinals. If there are two arguments, they must be strings of equal length, and in the resulting dictionary, each character in x will be mapped to the character at the same position in y. If there is a third argument, it must be a string, whose characters will be mapped to None in the result.
- partition(sep, /)¶
Partition the string into three parts using the given separator.
This will search for the separator in the string. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.
If the separator is not found, returns a 3-tuple containing the original string and two empty strings.
- removeprefix(prefix, /)¶
Return a str with the given prefix string removed if present.
If the string starts with the prefix string, return string[len(prefix):]. Otherwise, return a copy of the original string.
- removesuffix(suffix, /)¶
Return a str with the given suffix string removed if present.
If the string ends with the suffix string and that suffix is not empty, return string[:-len(suffix)]. Otherwise, return a copy of the original string.
- replace(old, new, count=-1, /)¶
Return a copy with all occurrences of substring old replaced by new.
- count
Maximum number of occurrences to replace. -1 (the default value) means replace all occurrences.
If the optional argument count is given, only the first count occurrences are replaced.
- rfind(sub[, start[, end]]) int ¶
Return the highest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation.
Return -1 on failure.
- rindex(sub[, start[, end]]) int ¶
Return the highest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation.
Raises ValueError when the substring is not found.
- rjust(width, fillchar=' ', /)¶
Return a right-justified string of length width.
Padding is done using the specified fill character (default is a space).
- rpartition(sep, /)¶
Partition the string into three parts using the given separator.
This will search for the separator in the string, starting at the end. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.
If the separator is not found, returns a 3-tuple containing two empty strings and the original string.
- rsplit(sep=None, maxsplit=-1)¶
Return a list of the words in the string, using sep as the delimiter string.
- sep
The delimiter according which to split the string. None (the default value) means split according to any whitespace, and discard empty strings from the result.
- maxsplit
Maximum number of splits to do. -1 (the default value) means no limit.
Splits are done starting at the end of the string and working to the front.
- rstrip(chars=None, /)¶
Return a copy of the string with trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
- split(sep=None, maxsplit=-1)¶
Return a list of the words in the string, using sep as the delimiter string.
- sep
The delimiter according which to split the string. None (the default value) means split according to any whitespace, and discard empty strings from the result.
- maxsplit
Maximum number of splits to do. -1 (the default value) means no limit.
- splitlines(keepends=False)¶
Return a list of the lines in the string, breaking at line boundaries.
Line breaks are not included in the resulting list unless keepends is given and true.
- startswith(prefix[, start[, end]]) bool ¶
Return True if S starts with the specified prefix, False otherwise. With optional start, test S beginning at that position. With optional end, stop comparing S at that position. prefix can also be a tuple of strings to try.
- strip(chars=None, /)¶
Return a copy of the string with leading and trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
- swapcase()¶
Convert uppercase characters to lowercase and lowercase characters to uppercase.
- title()¶
Return a version of the string where each word is titlecased.
More specifically, words start with uppercased characters and all remaining cased characters have lower case.
- translate(table, /)¶
Replace each character in the string using the given translation table.
- table
Translation table, which must be a mapping of Unicode ordinals to Unicode ordinals, strings, or None.
The table must implement lookup/indexing via __getitem__, for instance a dictionary or list. If this operation raises LookupError, the character is left untouched. Characters mapped to None are deleted.
- upper()¶
Return a copy of the string converted to uppercase.
- zfill(width, /)¶
Pad a numeric string with zeros on the left, to fill a field of the given width.
The string is never truncated.
- OPENTURNS = 'OTUniformDistribution'¶
- SCIPY = 'SPUniformDistribution'¶
- add_random_variable(name, distribution, size=1, interfaced_distribution='', interfaced_distribution_parameters=(), **parameters)¶
Add a random variable from a probability distribution.
- Parameters:
name (str) – The name of the random variable.
distribution (str) – The name of a class implementing a probability distribution, e.g.
"OTUniformDistribution"
or"SPUniformDistribution"
, or an interface to a library of probability distributions, e.g."OTDistribution"
or"SPDistribution"
.size (int) –
The dimension of the random variable. The parameters of the distribution are shared by all the components of the random variable.
By default it is set to 1.
interfaced_distribution (str) –
The name of the distribution in the library of probability distributions when
distribution
is the name of a class implementing an interface to this library.By default it is set to “”.
interfaced_distribution_parameters (tuple[Any] | StrKeyMapping) –
The parameters of the distribution in the library of probability distributions when
distribution
is the name of a class implementing an interface to this library; if empty, use the default ones.By default it is set to ().
**parameters (Any) – The parameters of the distribution; otherwise, use the default ones.
- Return type:
None
Warning
The probability distributions must have the same
DISTRIBUTION_FAMILY_ID
. For instance, one cannot mix a random variable distributed as anOTUniformDistribution
with identifier"OT"
and a random variable distributed as aSPNormalDistribution
with identifier"SP"
.
- add_random_vector(name, distribution, size=0, interfaced_distribution='', interfaced_distribution_parameters=(), **parameters)¶
Add a d-length random vector from a probability distribution.
Warning
The probability distributions must have the same
DISTRIBUTION_FAMILY_ID
. For instance, one cannot mix a random vector using aOTUniformDistribution
with identifier"OT"
and a random vector using aSPNormalDistribution
with identifier"SP"
.- Parameters:
name (str) – The name of the random vector.
distribution (str) – The name of a class implementing a probability distribution, e.g.
"OTUniformDistribution"
or"SPUniformDistribution"
, or an interface to a library of probability distributions, e.g."OTDistribution"
or"SPDistribution"
.size (int) –
The length d of the random vector. If
0
, deduce it from the parameters.By default it is set to 0.
interfaced_distribution (str) –
The name of the distribution in the library of probability distributions when
distribution
is the name of a class implementing an interface to this library.By default it is set to “”.
interfaced_distribution_parameters (tuple[list[Any]] | Mapping[str, list[Any]]) –
The parameters of the distribution in the library of probability distributions when
distribution
is the name of a class implementing an interface to this library. The values of the data structure (mapping or tuple) must be set either as[p_1,...,p_d]
(one value per component of the random vector) or as[p]
(one value for all the components) If empty, use the default ones.By default it is set to ().
**parameters (list[Any]) – The parameters of the distribution, either as
[p_1,...,p_d]
(one value per component of the random vector) or as[p]
(one value for all the components); otherwise, use the default ones.
- Raises:
ValueError – When mixing probability distributions from different families, e.g. an
OTDistribution
and aSPDistribution
or when the lengths of the distribution parameter collections are not consistent.- Return type:
None
- add_variable(name, size=1, var_type=_DesignVariableType.FLOAT, l_b=None, u_b=None, value=None)¶
Add a variable to the design space.
- Parameters:
name (str) – The name of the variable.
size (int) –
The size of the variable.
By default it is set to 1.
var_type (DesignVariableType | Sequence[DesignVariableType]) –
Either the type of the variable or the types of its components.
By default it is set to “float”.
l_b (Number | Iterable[Number] | None) – The lower bound of the variable. If
None
, use \(-\infty\).u_b (Number | Iterable[Number] | None) – The upper bound of the variable. If
None
, use \(+\infty\).value (Number | Iterable[Number] | None) – The default value of the variable. If
None
, do not use a default value.
- Raises:
ValueError – Either if the variable already exists or if the size is not a positive integer.
- Return type:
None
- array_to_dict(x_array)¶
Convert a design array into a dictionary indexed by the variables names.
- build_joint_distribution(copula=None)¶
Build the joint probability distribution.
- Parameters:
copula (Any | None) – A copula distribution defining the dependency structure between random variables; if
None
, consider an independent copula.- Return type:
None
- check()¶
Check the state of the design space.
- Raises:
ValueError – If the design space is empty.
- Return type:
None
- check_membership(x_vect, variable_names=None)¶
Check whether the variables satisfy the design space requirements.
- Parameters:
- Raises:
ValueError – Either if the dimension of the values vector is wrong, if the values are not specified as an array or a dictionary, if the values are outside the bounds of the variables or if the component of an integer variable is not an integer.
- Return type:
None
- clear() None. Remove all items from D. ¶
- compute_samples(n_samples=1, as_dict=False)¶
Sample the random variables and return the realizations.
- Parameters:
- Returns:
The realizations of the random variables, either stored in an array or in a dictionary whose values are the names of the random variables and the values are the evaluations.
- Return type:
- dict_to_array(design_values, variable_names=None)¶
Convert a mapping of design values into a NumPy array.
- Parameters:
- Returns:
The design values as a NumPy array.
- Return type:
ndarray
Notes
The data type of the returned NumPy array is the most general data type of the values of the mapping
design_values
corresponding to the keys iterable fromvariables_names
.
- evaluate_cdf(value, inverse=False)¶
Evaluate the cumulative density function (or its inverse) of each marginal.
- Parameters:
value (dict[str, ndarray]) – The values of the uncertain variables passed as a dictionary whose keys are the names of the variables.
inverse (bool) –
The type of function to evaluate. If
True
, compute the cumulative density function. Otherwise, compute the inverse cumulative density function.By default it is set to False.
- Returns:
A dictionary where the keys are the names of the random variables and the values are the evaluations.
- Return type:
- extend(other)¶
Extend the design space with another design space.
- Parameters:
other (DesignSpace) – The design space to be appended to the current one.
- Return type:
None
- extract_deterministic_space()¶
Define a new
DesignSpace
from the deterministic variables only.- Returns:
A
DesignSpace
defined by the deterministic variables only.- Return type:
- extract_uncertain_space(as_design_space=False)¶
Define a new
DesignSpace
from the uncertain variables only.- Parameters:
as_design_space (bool) –
If
False
, return aParameterSpace
containing the original uncertain variables as is; otherwise, return aDesignSpace
where the original uncertain variables are made deterministic. In that case, the bounds of a deterministic variable correspond to the limits of the support of the original probability distribution and the current value correspond to its mean.By default it is set to False.
- Returns:
A
ParameterSpace
defined by the uncertain variables only.- Return type:
- filter(keep_variables, copy=False)¶
Filter the design space to keep a subset of variables.
- Parameters:
- Returns:
Either the filtered original design space or a copy.
- Raises:
ValueError – If the variable is not in the design space.
- Return type:
- filter_dimensions(name, dimensions)¶
Filter the design space to keep a subset of dimensions for a variable.
- Parameters:
- Returns:
The filtered design space.
- Raises:
ValueError – If a dimension does not exist.
- Return type:
- classmethod from_csv(file_path, header=())¶
Create a design space from a CSV file.
- Parameters:
- Returns:
The design space defined in the file.
- Raises:
ValueError – If the file does not contain the minimal variables in its header.
- Return type:
- classmethod from_file(file_path, hdf_node_path='', **options)¶
Create a design space from a file.
- Parameters:
file_path (str | Path) – The path to the file. If the extension starts with “hdf”, the file will be considered as an HDF file.
hdf_node_path (str) –
The path of the HDF node from which the database should be imported. If empty, the root node is considered.
By default it is set to “”.
**options (Any) – The keyword reading options.
- Returns:
The design space defined in the file.
- Return type:
- classmethod from_hdf(file_path, hdf_node_path='')¶
Create a design space from an HDF file.
- Parameters:
- Returns:
The design space defined in the file.
- Return type:
- get(k[, d]) D[k] if k in D, else d. d defaults to None. ¶
- get_active_bounds(x_vec=None, tol=1e-08)¶
Determine which bound constraints of a design value are active.
- Parameters:
x_vec (ndarray | None) – The design value at which to check the bounds. If
None
, use the current design value.tol (float) –
The tolerance of comparison of a scalar with a bound.
By default it is set to 1e-08.
- Returns:
Whether the components of the lower and upper bound constraints are active, the first returned value representing the lower bounds and the second one the upper bounds, e.g.
( { "x": array(are_x_lower_bounds_active), "y": array(are_y_lower_bounds_active), }, { "x": array(are_x_upper_bounds_active), "y": array(are_y_upper_bounds_active), }, )
where:
are_x_lower_bounds_active = [True, False] are_x_upper_bounds_active = [False, False] are_y_lower_bounds_active = [False] are_y_upper_bounds_active = [True]
- Return type:
- get_current_value(variable_names=None, complex_to_real=False, as_dict=False, normalize=False)¶
Return the current design value.
If the names of the variables are empty then an empty data is returned.
- Parameters:
variable_names (Sequence[str] | None) – The names of the design variables. If
None
, use all the design variables.complex_to_real (bool) –
Whether to cast complex numbers to real ones.
By default it is set to False.
as_dict (bool) –
Whether to return the current design value as a dictionary of the form
{variable_name: variable_value}
.By default it is set to False.
normalize (bool) –
Whether to normalize the design values in \([0,1]\) with the bounds of the variables.
By default it is set to False.
- Returns:
The current design value.
- Raises:
ValueError – If names in
variable_names
are not in the design space.- Return type:
Warning
For performance purposes,
get_current_value()
does not return a copy of the current value. This means that modifying the returned object will make theDesignSpace
inconsistent (the current design value stored as a NumPy array and the current design value stored as a dictionary of NumPy arrays will be different). To modify the returned object without impacting theDesignSpace
, you shall copy this object and modify the copy.See also
To modify the current value, please use
set_current_value()
orset_current_variable()
.
- get_indexed_var_name(variable_name)¶
Create the names of the components of a variable.
If the size of the variable is equal to 1, this method returns the name of the variable. Otherwise, it concatenates the name of the variable, the separator
DesignSpace.SEP
and the index of the component.
- get_indexed_variable_names()¶
Create the names of the components of all the variables.
If the size of the variable is equal to 1, this method uses its name. Otherwise, it concatenates the name of the variable, the separator
DesignSpace.SEP
and the index of the component.
- get_lower_bound(name)¶
Return the lower bound of a variable.
- Parameters:
name (str) – The name of the variable.
- Returns:
The lower bound of the variable (possibly infinite).
- Return type:
ndarray | None
- get_lower_bounds(variable_names=None, as_dict=False)¶
Return the lower bounds of design variables.
- Parameters:
- Returns:
The lower bounds of the design variables.
- Return type:
- get_pretty_table(fields=(), with_index=False, capitalize=False, simplify=False)¶
Build a tabular view of the design space.
- Parameters:
fields (Sequence[str]) –
The name of the fields to be exported. If empty, export all the fields.
By default it is set to ().
with_index (bool) –
Whether to show index of names for arrays. This is ignored for scalars.
By default it is set to False.
capitalize (bool) –
Whether to capitalize the field names and replace
"_"
by" "
.By default it is set to False.
simplify (bool) –
Whether to return a simplified tabular view.
By default it is set to False.
- Returns:
A tabular view of the design space.
- Return type:
- get_range(variable)¶
Return the numerical range of a random variable.
- get_size(name)¶
Get the size of a variable.
- get_support(variable)¶
Return the mathematical support of a random variable.
- get_tabular_view(decimals=2)¶
Return a tabular view of the parameter space.
This view contains statistical information.
- get_type(name)¶
Return the type of a variable.
- get_upper_bound(name)¶
Return the upper bound of a variable.
- Parameters:
name (str) – The name of the variable.
- Returns:
The upper bound of the variable (possibly infinite).
- Return type:
ndarray | None
- get_upper_bounds(variable_names=None, as_dict=False)¶
Return the upper bounds of design variables.
- Parameters:
- Returns:
The upper bounds of the design variables.
- Return type:
- get_variables_indexes(variable_names, use_design_space_order=True)¶
Return the indexes of a design array corresponding to variables names.
- Parameters:
variable_names (Iterable[str]) – The names of the variables.
use_design_space_order (bool) –
Whether to order the indexes according to the order of the variables names in the design space. Otherwise the indexes will be ordered in the same order as the variables names were required.
By default it is set to True.
- Returns:
The indexes of a design array corresponding to the variables names.
- Return type:
NDArray[int]
- has_current_value()¶
Check if each variable has a current value.
- Returns:
Whether the current design value is defined for all variables.
- Return type:
- has_integer_variables()¶
Check if the design space has at least one integer variable.
- Returns:
Whether the design space has at least one integer variable.
- Return type:
- static init_from_dataset(dataset, groups=None, uncertain=None, copula=None)¶
Initialize the parameter space from a dataset.
- Parameters:
dataset (Dataset) – The dataset used for the initialization.
groups (Iterable[str] | None) – The groups of the dataset to be considered. If
None
, consider all the groups.uncertain (Mapping[str, bool] | None) – Whether the variables should be uncertain or not.
copula (Any) – A name of copula defining the dependency between random variables.
- Return type:
- initialize_missing_current_values()¶
Initialize the current values of the design variables when missing.
Use:
the center of the design space when the lower and upper bounds are finite,
the lower bounds when the upper bounds are infinite,
the upper bounds when the lower bounds are infinite,
zero when the lower and upper bounds are infinite.
- Return type:
None
- is_deterministic(variable)¶
Check if a variable is deterministic.
- is_uncertain(variable)¶
Check if a variable is uncertain.
- items() a set-like object providing a view on D's items ¶
- keys() a set-like object providing a view on D's keys ¶
- normalize_grad(g_vect)¶
Normalize an unnormalized gradient.
This method is based on the chain rule:
\[\frac{df(x)}{dx} = \frac{df(x)}{dx_u}\frac{dx_u}{dx} = \frac{df(x)}{dx_u}\frac{1}{u_b-l_b}\]where \(x_u = \frac{x-l_b}{u_b-l_b}\) is the normalized input vector, \(x\) is the unnormalized input vector and \(l_b\) and \(u_b\) are the lower and upper bounds of \(x\).
Then, the normalized gradient reads:
\[\frac{df(x)}{dx_u} = (u_b-l_b)\frac{df(x)}{dx}\]where \(\frac{df(x)}{dx}\) is the unnormalized one.
- Parameters:
g_vect (RealOrComplexArrayT) – The gradient to be normalized.
- Returns:
The normalized gradient.
- Return type:
- normalize_vect(x_vect, minus_lb=True, use_dist=False, out=None)¶
Normalize a vector of the parameter space.
If use_dist is True, use the cumulative probability distributions of the random variables to scale the components of the random variables between 0 and 1. Otherwise, use the approach defined in
DesignSpace.normalize_vect()
with minus_lb.For the components of the deterministic variables, use the approach defined in
DesignSpace.normalize_vect()
with minus_lb.- Parameters:
x_vect (ndarray) – The values of the design variables.
minus_lb (bool) –
If
True
, remove the lower bounds at normalization.By default it is set to True.
use_dist (bool) –
If
True
, normalize the components of the random variables with their cumulative probability distributions.By default it is set to False.
out (ndarray | None) – The array to store the normalized vector. If
None
, create a new array.
- Returns:
The normalized vector.
- Return type:
ndarray
- pop(k[, d]) v, remove specified key and return the corresponding value. ¶
If key is not found, d is returned if given, otherwise KeyError is raised.
- popitem() (k, v), remove and return some (key, value) pair ¶
as a 2-tuple; but raise KeyError if D is empty.
- project_into_bounds(x_c, normalized=False)¶
Project a vector onto the bounds, using a simple coordinate wise approach.
- remove_variable(name)¶
Remove a variable from the probability space.
- Parameters:
name (str) – The name of the variable.
- Return type:
None
- rename_variable(current_name, new_name)¶
Rename a variable.
- round_vect(x_vect, copy=True)¶
Round the vector where variables are of integer type.
- set_current_value(value)¶
Set the current design value.
- Parameters:
value (ndarray | Mapping[str, ndarray] | OptimizationResult) – The value of the current design.
- Raises:
ValueError – If the value has a wrong dimension.
TypeError – If the value is neither a mapping of NumPy arrays, a NumPy array nor an
OptimizationResult
.
- Return type:
None
- set_current_variable(name, current_value)¶
Set the current value of a single variable.
- set_lower_bound(name, lower_bound)¶
Set the lower bound of a variable.
- Parameters:
name (str) – The name of the variable.
lower_bound (ndarray | None) – The value of the lower bound.
- Raises:
ValueError – If the variable does not exist.
- Return type:
None
- set_upper_bound(name, upper_bound)¶
Set the upper bound of a variable.
- Parameters:
name (str) – The name of the variable.
upper_bound (ndarray | None) – The value of the upper bound.
- Raises:
ValueError – If the variable does not exist.
- Return type:
None
- setdefault(k[, d]) D.get(k,d), also set D[k]=d if k not in D ¶
- to_complex()¶
Cast the current value to complex.
- Return type:
None
- to_csv(output_file, fields=(), header_char='', **table_options)¶
Export the design space to a CSV file.
- Parameters:
output_file (str | Path) – The path to the file.
fields (Sequence[str]) –
The fields to be exported. If empty, export all fields.
By default it is set to ().
header_char (str) –
The header character.
By default it is set to “”.
**table_options (Any) – The names and values of additional attributes for the
PrettyTable
view generated byDesignSpace.get_pretty_table()
.
- Return type:
None
- to_design_space()¶
Convert the parameter space into a
DesignSpace
.The original deterministic variables are kept as is while the original uncertain variables are made deterministic. In that case, the bounds of a deterministic variable correspond to the limits of the support of the original probability distribution and the current value correspond to its mean.
- Returns:
A
DesignSpace
where all original variables are made deterministic.- Return type:
- to_file(file_path, **options)¶
Save the design space.
- Parameters:
file_path (str | Path) – The file path to save the design space. If the extension starts with “hdf”, the design space will be saved in an HDF file.
**options – The keyword reading options.
- Return type:
None
- to_hdf(file_path, append=False, hdf_node_path='')¶
Export the design space to an HDF file.
- Parameters:
file_path (str | Path) – The path to the file to export the design space.
append (bool) –
If
True
, appends the data in the file.By default it is set to False.
hdf_node_path (str) –
The path of the HDF node in which the design space should be exported. If empty, the root node is considered.
By default it is set to “”.
- Return type:
None
- transform_vect(vector, out=None)¶
Map a point of the design space to a vector with components in \([0,1]\).
- Parameters:
vector (ndarray) – A point of the design space.
out (ndarray | None) – The array to store the transformed vector. If
None
, create a new array.
- Returns:
A vector with components in \([0,1]\).
- Return type:
ndarray
- unnormalize_grad(g_vect)¶
Unnormalize a normalized gradient.
This method is based on the chain rule:
\[\frac{df(x)}{dx} = \frac{df(x)}{dx_u}\frac{dx_u}{dx} = \frac{df(x)}{dx_u}\frac{1}{u_b-l_b}\]where \(x_u = \frac{x-l_b}{u_b-l_b}\) is the normalized input vector, \(x\) is the unnormalized input vector, \(\frac{df(x)}{dx_u}\) is the unnormalized gradient \(\frac{df(x)}{dx}\) is the normalized one, and \(l_b\) and \(u_b\) are the lower and upper bounds of \(x\).
- Parameters:
g_vect (RealOrComplexArrayT) – The gradient to be unnormalized.
- Returns:
The unnormalized gradient.
- Return type:
- unnormalize_vect(x_vect, minus_lb=True, no_check=False, use_dist=False, out=None)¶
Unnormalize a normalized vector of the parameter space.
If
use_dist
is True, use the inverse cumulative probability distributions of the random variables to unscale the components of the random variables. Otherwise, use the approach defined inDesignSpace.unnormalize_vect()
with minus_lb and no_check.For the components of the deterministic variables, use the approach defined in
DesignSpace.unnormalize_vect()
with minus_lb and no_check.- Parameters:
x_vect (ndarray) – The values of the design variables.
minus_lb (bool) –
Whether to remove the lower bounds at normalization.
By default it is set to True.
no_check (bool) –
Whether to check if the components are in \([0,1]\).
By default it is set to False.
use_dist (bool) –
Whether to unnormalize the components of the random variables with their inverse cumulative probability distributions.
By default it is set to False.
out (ndarray | None) – The array to store the unnormalized vector. If
None
, create a new array.
- Returns:
The unnormalized vector.
- Return type:
ndarray
- untransform_vect(vector, no_check=False, out=None)¶
Map a vector with components in \([0,1]\) to the design space.
- Parameters:
vector (ndarray) – A vector with components in \([0,1]\).
no_check (bool) –
Whether to check if the components are in \([0,1]\).
By default it is set to False.
out (ndarray | None) – The array to store the untransformed vector. If
None
, create a new array.
- Returns:
A point of the variables space.
- Return type:
ndarray
- update([E, ]**F) None. Update D from mapping/iterable E and F. ¶
If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
- values() an object providing a view on D's values ¶
- DESIGN_SPACE_GROUP = 'design_space'¶
- LB_GROUP = 'l_b'¶
- NAMES_GROUP = 'names'¶
- NAME_GROUP = 'name'¶
- SEP = '!'¶
- SIZE_GROUP = 'size'¶
- UB_GROUP = 'u_b'¶
- VALUE_GROUP = 'value'¶
- VARIABLE_TYPES_TO_DTYPES: Final[dict[str, str]] = {_DesignVariableType.FLOAT: 'float64', _DesignVariableType.INTEGER: 'int32'}¶
One NumPy
dtype
per design variable type.
- VAR_TYPE_GROUP = 'var_type'¶
- dimension: int¶
The total dimension of the space, corresponding to the sum of the sizes of the variables.
- distribution: BaseJointDistribution¶
The joint probability distribution of the uncertain variables.
- distributions: dict[str, BaseJointDistribution]¶
The marginal probability distributions of the uncertain variables.
These variables are defined as random vectors with independent components.
- normalize: dict[str, ndarray]¶
The normalization policies of the variables components indexed by the variables names; if True, the component can be normalized.
- variable_types: dict[str, ndarray]¶
The types of the variables components, which can be any
DesignSpace.DesignVariableType
.