Parameter space¶
The class ParameterSpace¶
Variable space defining both deterministic and uncertain variables.
Overview¶
The ParameterSpace
class describes a set of parameters of interest
which can be either deterministic or uncertain.
This class inherits from DesignSpace
.
Capabilities¶
The DesignSpace.add_variable()
aims to add deterministic variables from:
a variable name,
an optional variable size (default: 1),
an optional variable type (default: float),
an optional lower bound (default: - infinity),
an optional upper bound (default: + infinity),
an optional current value (default: None).
The add_random_variable()
aims to add uncertain
variables (a.k.a. random variables) from:
a variable name,
a distribution name (see
get_available_distributions()
),an optional variable size,
optional distribution parameters (
parameters
set as a tuple of positional arguments forOTDistribution
or a dictionary of keyword arguments forSPDistribution
, or keyword arguments for standard probability distribution such asOTNormalDistribution
andSPNormalDistribution
).
The ParameterSpace
also provides the following methods:
compute_samples()
: returns several samples of the uncertain variables,evaluate_cdf()
: evaluate the cumulative density function for the different variables and their differentget_range()
returns the numerical range of the different uncertain parameters,get_support()
: returns the mathematical support of the different uncertain variables,is_uncertain()
: checks if a parameter is uncertain,is_deterministic()
: checks if a parameter is deterministic.
Classes:
|
Parameter space. |
- class gemseo.algos.parameter_space.ParameterSpace(copula='independent_copula')[source]
Parameter space.
- Attributes
uncertain_variables (List(str)) – The names of the uncertain variables.
distributions (Dict(str,Distribution)) – The marginal probability distributions of the uncertain variables.
distribution (ComposedDistribution) – The joint probability distribution of the uncertain variables.
- Parameters
copula (str) – A name of copula defining the dependency between random variables.
- Return type
None
Methods:
add_random_variable
(name, distribution[, size])Add a random variable from a probability distribution.
add_variable
(name[, size, var_type, l_b, …])Add a variable to the design space.
array_to_dict
(x_array)Split the current point into a dictionary with variables names.
check
()Check the state of the design space.
check_membership
(x_vect[, variables_names])Checks whether the input variables satisfy the design space requirements.
compute_samples
([n_samples, as_dict])Sample the random variables and return the realizations.
dict_to_array
(x_dict[, all_vars, all_var_list])Aggregate a point as dictionary into array.
evaluate_cdf
(value[, inverse])Evaluate the cumulative density function (or its inverse) of each marginal.
export_hdf
(file_path[, append])Export to hdf file.
export_to_txt
(output_file[, fields, header_char])Exports the design space to a text file.
extend
(other)Extend the design space with another design space.
Extract the deterministic space.
Extract the uncertain space.
filter
(keep_variables[, copy])Filter the design space to keep a sublist of variables.
filter_dim
(variable, keep_dimensions)Filters the design space to keep a sublist of dimensions for a given variable.
get_active_bounds
([x_vec, tol])Determine which bound constraints of the current point are active.
get_current_x
([variables_names])Gets the current point in the design space.
Get the current point in the design space.
Returns the current point normalized.
get_indexed_var_name
(variable_name)Return a list of the variables names with their indices such as.
Return a list of the variables names with their indices such as.
get_lower_bound
(name)Gets the lower bound of a variable.
get_lower_bounds
([variables_names])Generates an array of the variables’ lower bounds.
get_pretty_table
([fields])Builds a PrettyTable object from the design space data.
get_range
(variable)Return the numerical range of a random variable.
get_size
(name)Get the size of a variable Return None if the variable is not known.
get_support
(variable)Return the mathematical support of a random variable.
get_tabular_view
([decimals])Return a tabular view of the parameter space.
get_type
(name)Get the type of a variable Return None if the variable is not known.
get_upper_bound
(name)Gets the upper bound of a variable.
get_upper_bounds
([variables_names])Generates an array of the variables’ upper bounds.
get_variables_indexes
(variables_names)Return the indexes of a design array corresponding to the variables names.
Tests if current_x is defined.
import_hdf
(file_path)Imports design space from hdf file.
init_from_dataset
(dataset[, groups, …])Initialize the parameter space from a dataset.
is_deterministic
(variable)Check if a variable is deterministic.
is_uncertain
(variable)Check if a variable is uncertain.
normalize_vect
(x_vect[, minus_lb, use_dist])Normalize a vector.
project_into_bounds
(x_c[, normalized])Projects x_c onto the bounds, using a simple coordinate wise approach.
read_from_txt
(input_file[, header])Parses a csv file to read the DesignSpace.
remove_variable
(name)Remove a variable from the probability space.
round_vect
(x_vect)Rounds the vector where variables are of integer type.
set_current_variable
(name, current_value)Set the current value of a single variable.
set_current_x
(current_x)Set the current point.
set_lower_bound
(name, lower_bound)Set a new lower bound for variable name.
set_upper_bound
(name, upper_bound)Set a new upper bound for variable name.
Casts the current value to complex.
unnormalize_vect
(x_vect[, minus_lb, …])Unnormalize an unit vector.
Attributes:
The deterministic variables.
- add_random_variable(name, distribution, size=1, **parameters)[source]
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 ‘SPDistribution’.
size (int) – The dimension of the random variable.
**parameters – The parameters of the distribution.
parameters (Union[int, Tuple[str, int, float], Mapping[str, Union[str, int, float]], None, float]) –
- Return type
None
- add_variable(name, size=1, var_type='float', l_b=None, u_b=None, value=None)
Add a variable to the design space.
- Parameters
name – param size: (Default value = 1)
var_type – Default value = FLOAT)
l_b – Default value = None)
u_b – Default value = None)
value – Default value = None)
size – (Default value = 1)
- array_to_dict(x_array)
Split the current point into a dictionary with variables names.
- Parameters
x_array – x array to be converted to a dict of array
- check()
Check the state of the design space.
- check_membership(x_vect, variables_names=None)
Checks whether the input variables satisfy the design space requirements.
- Parameters
x_vect (dict or array) – design variables
variables_names – names of the variables to be checked
- compute_samples(n_samples=1, as_dict=False)[source]
Sample the random variables and return the realizations.
- Parameters
n_samples (int) – A number of samples.
as_dict (bool) – The type of the returned object. If True, return a dictionary. Otherwise, return an array.
- 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
Union[Dict[str, numpy.ndarray], numpy.ndarray]
- property deterministic_variables
The deterministic variables.
- dict_to_array(x_dict, all_vars=True, all_var_list=None)
Aggregate a point as dictionary into array.
- Parameters
x_dict – point as dictionary
all_vars – if True, all variables shall be in x_dict
all_var_list – list of whole set of variables, if None, use self.variables_names
- evaluate_cdf(value, inverse=False)[source]
Evaluate the cumulative density function (or its inverse) of each marginal.
- Parameters
value (Dict[str, numpy.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.
- Returns
- A dictionary where the keys are the names of the random variables
and the values are the evaluations.
- Return type
Dict[str, numpy.ndarray]
- export_hdf(file_path, append=False)
Export to hdf file.
- Parameters
file_path – path to file to write
append – if True, appends the data in the file
- export_to_txt(output_file, fields=None, header_char='', **table_options)
Exports the design space to a text file.
- Parameters
output_file – output file path
fields – list of fields to export, by default all
- extend(other)
Extend the design space with another design space.
- Parameters
other (DesignSpace) – design space to be appended
- extract_deterministic_space()[source]
Extract the deterministic space.
- Returns
The deterministic space.
- Return type
- extract_uncertain_space()[source]
Extract the uncertain space.
- Returns
The uncertain space.
- Return type
- filter(keep_variables, copy=False)
Filter the design space to keep a sublist of variables.
- Parameters
keep_variables (str of list(str)) – the list of variables to keep
copy (bool) – if True then a copy of the design space is filtered, otherwise the design space itself is filtered
- Returns
the filtered design space (or a copy)
- Return type
- filter_dim(variable, keep_dimensions)
Filters the design space to keep a sublist of dimensions for a given variable.
- Parameters
variable – the variable
keep_dimensions – the list of dimension to keep
- get_active_bounds(x_vec=None, tol=1e-08)
Determine which bound constraints of the current point are active.
- Parameters
x_vec – the point at which we check the bounds
tol – tolerance of comparison of a scalar with a bound (Default value = 1e-8)
- get_current_x(variables_names=None)
Gets the current point in the design space.
- Parameters
variables_names (list(str)) – names of the required variables, optional
- Returns
the x vector as array
- Return type
ndarray
- get_current_x_dict()
Get the current point in the design space.
- Returns
the x vector as a dict, keys are the variable names values are the variable vales as np array
- get_current_x_normalized()
Returns the current point normalized.
- Returns
the x vector as array normalized by the bounds
- get_indexed_var_name(variable_name)
Return a list of the variables names with their indices such as.
[x!0,x!1,y,z!0,z!1]
- Parameters
variable_name (str) – name of the variable
- Returns
names of the variable components
- Return type
list(str)
- get_indexed_variables_names()
Return a list of the variables names with their indices such as.
[x!0,x!1,y,z!0,z!1]
- Returns
names of all the variables components
- Return type
list(str)
- get_lower_bound(name)
Gets the lower bound of a variable.
- Parameters
name – variable name
- Returns
variable lower bound (possibly infinite)
- get_lower_bounds(variables_names=None)
Generates an array of the variables’ lower bounds.
- Parameters
variables_names – names of the variables of which the lower bounds are required
- get_pretty_table(fields=None)
Builds a PrettyTable object from the design space data.
- Parameters
fields – list of fields to export, by default all
- Returns
the pretty table object
- get_range(variable)[source]
Return the numerical range of a random variable.
- Parameters
variable (str) – The name of the random variable.
- Returns
The range of the components of the random variable.
- Return type
List[numpy.ndarray]
- get_size(name)
Get the size of a variable Return None if the variable is not known.
- Parameters
name – name of the variable
- get_support(variable)[source]
Return the mathematical support of a random variable.
- Parameters
variable (str) – The name of the random variable.
- Returns
The support of the components of the random variable.
- Return type
List[numpy.ndarray]
- get_tabular_view(decimals=2)[source]
Return a tabular view of the parameter space.
This view contains statistical information.
- Parameters
decimals (int) – The number of decimals to print.
- Returns
The tabular view.
- Return type
str
- get_type(name)
Get the type of a variable Return None if the variable is not known.
- Parameters
name – name of the variable
- get_upper_bound(name)
Gets the upper bound of a variable.
- Parameters
name – variable name
- Returns
variable upper bound (possibly infinite)
- get_upper_bounds(variables_names=None)
Generates an array of the variables’ upper bounds.
- Parameters
variables_names – names of the variables of which the upper bounds are required
- get_variables_indexes(variables_names)
Return the indexes of a design array corresponding to the variables names.
- Parameters
variables_names (list(str)) – names of the variables
- Returns
indexes of a design array corresponding to the variables names
- Return type
ndarray
- has_current_x()
Tests if current_x is defined.
- Returns
True if current_x is defined
- import_hdf(file_path)
Imports design space from hdf file.
- Parameters
file_path –
- static init_from_dataset(dataset, groups=None, uncertain=None, copula='independent_copula')[source]
Initialize the parameter space from a dataset.
- Parameters
dataset (Dataset) – The dataset used for the initialization.
groups (Optional[Iterable[str]]) – The groups of the dataset to be considered. If None, consider all the groups.
uncertain (Optional[Mapping[str,bool]]) – Whether the variables should be uncertain or not.
copula (str) – A name of copula defining the dependency between random variables.
- Return type
- is_deterministic(variable)[source]
Check if a variable is deterministic.
- Parameters
variable (str) – The name of the variable.
- Returns
True is the variable is deterministic.
- Return type
bool
- is_uncertain(variable)[source]
Check if a variable is uncertain.
- Parameters
variable (str) – The name of the variable.
- Returns
True is the variable is uncertain.
- Return type
bool
- normalize_vect(x_vect, minus_lb=True, use_dist=False)[source]
Normalize a vector.
- Parameters
x_vect (numpy.ndarray) – The vector to normalize.
minus_lb (bool) – The type of normalization. If True, remove lower bounds at normalization.
no_check – The data checker. If True, do not check that values are in [0,1].
use_dist (bool) – The statistical scaling. If True, rescale wrt the statistical law.
- Returns
The normalized vector.
- Return type
numpy.ndarray
- project_into_bounds(x_c, normalized=False)
Projects x_c onto the bounds, using a simple coordinate wise approach.
- Parameters
normalized (bool) – if True then the vector is assumed to be normalized
x_c – x vector (np array)
- Returns
projected x_c
- static read_from_txt(input_file, header=None)
Parses a csv file to read the DesignSpace.
- Parameters
input_file – returns: s: the design space
header – fields list, or by default, read in the file
- Returns
the design space
- remove_variable(name)[source]
Remove a variable from the probability space.
- Parameters
name (str) – The name of the variable.
- Return type
None
- round_vect(x_vect)
Rounds the vector where variables are of integer type.
- Parameters
x_vect – design variables to round
- set_current_variable(name, current_value)
Set the current value of a single variable.
- Parameters
name – name of the variable
current_value – current value of the variable
- set_current_x(current_x)
Set the current point.
- Parameters
current_x – the current design vector
- set_lower_bound(name, lower_bound)
Set a new lower bound for variable name.
- Parameters
name – name of the variable
lower_bound – lower bound
- set_upper_bound(name, upper_bound)
Set a new upper bound for variable name.
- Parameters
name – name of the variable
upper_bound – upper bound
- to_complex()
Casts the current value to complex.
- unnormalize_vect(x_vect, minus_lb=True, no_check=False, use_dist=True)[source]
Unnormalize an unit vector.
- Parameters
x_vect (numpy.ndarray) – The unit vector to unnormalize.
minus_lb (bool) – The type of normalization. If True, remove lower bounds at normalization.
no_check (bool) – The data checker. If True, do not check that values are in [0,1].
use_dist (bool) – The statistical scaling. If True, rescale wrt the statistical law.
- Returns
The unnormalized vector.
- Return type
numpy.ndarray