design_space module¶
Design space¶
A design space is used to represent the optimization’s unknowns,
a.k.a. design variables. A DesignSpace
describes
this design space at a given state, in terms of names, sizes, types, bounds
and current values of the design variables. Variables can easily be added to
the DesignSpace
using the DesignSpace.add_variable()
method
or removed using the DesignSpace.remove_variable()
method. We can also
filter the design variables using the DesignSpace.filter()
method.
Getters and setters are also available to get or set the value of a given
variable property. Lastly, an instance of DesignSpace
can be stored
in a txt or HDF file.
-
class
gemseo.algos.design_space.
DesignSpace
(hdf_file=None)[source]¶ Bases:
object
Class that describes the design space at a given state: the names/sizes/types/bounds of the variables and the initial solution of the optimization problem
Constructor
-
AVAILABLE_TYPES
= ['float', 'integer']¶
-
DESIGN_SPACE_GROUP
= 'design_space'¶
-
FLOAT
= 'float'¶
-
INTEGER
= 'integer'¶
-
LB_GROUP
= 'l_b'¶
-
MINIMAL_FIELDS
= ['name', 'lower_bound', 'upper_bound']¶
-
NAMES_GROUP
= 'names'¶
-
SEP
= '!'¶
-
SIZE_GROUP
= 'size'¶
-
TABLE_NAMES
= ['name', 'lower_bound', 'value', 'upper_bound', 'type']¶
-
UB_GROUP
= 'u_b'¶
-
VALUE_GROUP
= 'value'¶
-
VAR_TYPE_GROUP
= 'var_type'¶
-
add_variable
(name, size=1, var_type='float', l_b=None, u_b=None, value=None)[source]¶ 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)[source]¶ Split the current point into a dictionary with variables names
- Parameters
x_array – x array to be converted to a dict of array
-
check_membership
(x_vect, variables_names=None)[source]¶ 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
-
dict_to_array
(x_dict, all_vars=True, all_var_list=None)[source]¶ 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
-
export_hdf
(file_path, append=False)[source]¶ 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)[source]¶ Exports the design space to a text file
- Parameters
output_file – output file path
fields – list of fields to export, by default all
-
filter
(keep_variables)[source]¶ Filters the design space to keep a sublist of variables
- Parameters
keep_variables – the list of variables to keep
-
filter_dim
(variable, keep_dimensions)[source]¶ 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)[source]¶ 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)[source]¶ 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
()[source]¶ 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
()[source]¶ Returns the current point normalized.
- Returns
the x vector as array normalized by the bounds
-
get_indexed_var_name
(variable_name)[source]¶ Retuns a list of the variables names with their indices such as [x!0,x!1,y,z!0,z!1]
-
get_indexed_variables_names
()[source]¶ Retuns a list of the variables names with their indices such as [x!0,x!1,y,z!0,z!1]
-
get_lower_bound
(name)[source]¶ Gets the lower bound of a variable.
- Parameters
name – variable name
- Returns
variable lower bound (possibly infinite)
-
get_lower_bounds
(variables_names=None)[source]¶ 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)[source]¶ 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_size
(name)[source]¶ Get the size of a variable Return None if the variable is not known
- Parameters
name – name of the variable
-
get_type
(name)[source]¶ Get the type of a variable Return None if the variable is not known
- Parameters
name – name of the variable
-
get_upper_bound
(name)[source]¶ Gets the upper bound of a variable.
- Parameters
name – variable name
- Returns
variable upper bound (possibly infinite)
-
get_upper_bounds
(variables_names=None)[source]¶ Generates an array of the variables’ upper bounds.
- Parameters
variables_names – names of the variables of which the upper bounds are required
-
normalize_vect
(x_vect, minus_lb=True)[source]¶ Normalizes a vector of the design space. Unbounded variables are not normalized.
- Parameters
x_vect (ndarray) – design variables
minus_lb – if True, remove lower bounds at normalization
- Returns
normalized vector
-
project_into_bounds
(x_c, normalized=False)[source]¶ Projects x_c onto the bounds, using a simple coordinate wise approach
- Parameters
x_c – x vector (np array)
- Returns
projected x_c
-
static
read_from_txt
(input_file, header=None)[source]¶ 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 (and bounds and types) from the design space
- Parameters
name – name of the variable to remove
-
round_vect
(x_vect)[source]¶ Rounds the vector where variables are of integer type
- Parameters
x_vect – design variables to round
-
set_current_variable
(name, current_value)[source]¶ 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)[source]¶ Set the current point
- Parameters
current_x – the current design vector
-
set_lower_bound
(name, lower_bound)[source]¶ Set a new lower bound for variable name
- Parameters
name – name of the variable
lower_bound – lower bound
-
set_upper_bound
(name, upper_bound)[source]¶ Set a new upper bound for variable name
- Parameters
name – name of the variable
upper_bound – upper bound
-
unnormalize_vect
(x_vect, minus_lb=True, no_check=False)[source]¶ Unnormalizes a normalized vector of the design space.
- Parameters
x_vect (ndarray) – design variables
minus_lb – if True, remove lower bounds at normalization
no_check – if True, dont check that values are in [0,1]
- Returns
normalized vector
-