ClearVu Design Space package
cvds.CvdsBase module
This module contains basic classes and functions.
- class cvds.CvdsBase.Manager(*args, **kwargs)
Bases:
BaseManagerClass to connect to the CVDS C++ core and manage models. The optional parameters are:
with_flask: If you want to use user models with self implemented modeling algorithms, the package needs to start a flask service. Alternatively, you can start the service later with
start_model_service().flask_port: This is the port used with the flask service for user models. Default is 5000.
- create_solution_space_optimizer()
Create a new solution space optimizer and return it.
- Returns:
The new solution space optimizer.
- exit()
Disconnect from core and release license
- init()
Reconnect to core and block license
- load_solution_space_optimizer(pickle_file)
Load a solution space optimizer from a pickle file.
- Parameters:
pickle_file – The name of the pickle file.
- Returns:
The unpickled solution space optimizer.
- Raises:
CvaException – if the pickle does not contain a solution space optimizer.
- cvds.CvdsBase.html_help()
Open the html help in the default browser
cvds.Examples module
- cvds.Examples.data_artificial()
Creates an example data frame with information on inputs and outputs.
The example data has 14 input variables X01-X13 and XC. X01-X13 are real-valued variables all in the range from 0.0 to 1.0. XC is a class variable with to attributes ON and OFF. There are two output variables. Y is real-valued and YC is a class variable with five attributes A-E. There are also some missing values present.
- Returns:
A dictionary containing the pandas.DataFrame (df), the input variable names (input_variable_names) and the output variable names (output_variable_names).
- Return type:
DataFrame
- cvds.Examples.data_rosenbrock(size=100)
Creates an example data frame with values for inputs and outputs.
The example data is generated by using the two dimensional Rosenbrock function
\[y = f(x_1 \cdots x_n) = \sum_{i=1}^{n-1} (100(x_i^2 - x_{i+1})^2 + (1-x_i)^2) \text{ with } n = 2\]- Parameters:
size (int) – Number of sample points.
- Returns:
A dictionary containing the pandas.DataFrame (df), the input variable names (input_variable_names) and the output variable names (output_variable_names).
- Return type:
Dict[str, object]
- cvds.Examples.function_restriction(vector)
Very simple function to calculate a restriction value. Used in optimization example with
1optimization.add_restriction('example_restriction', '>', 5.0)
meaning that the result of this function has to be > 5.0. Otherwise
vectorwill not be a valid solution for the optimization.- Parameters:
vector (List[float]) – n-dimensional vector with n >= 2.
- Returns:
Sum of first two entries.
- Return type:
float
- cvds.Examples.function_rosenbrock(vector)
Calculates the Rosenbrock function for an n-dimensional input vector.
- Parameters:
vector (List[float]) – Vector of input values.
- Returns:
- \[y = f(x_1 \cdots x_n) = \sum_{i=1}^{n-1} (100(x_i^2 - x_{i+1})^2 + (1-x_i)^2)\]
- Return type:
float
- cvds.Examples.function_sphere(vector)
Calculates the sum of squares.
The n-dimensional sphere function:
\[y = f(x_1 \cdots x_n) = \sum_{i=1}^{n} x_i^2\]- Parameters:
vector (List[float]) – Vector of input values.
- Returns:
Result of the n-dimensional sphere function (sum of squares).
- Return type:
float
- cvds.Examples.optimization_multi_objective_evaluation(dataFrame)
Applies the function
function_sphere()andfunction_restriction()to a data frame.A column with all output values will be added to the data frame. Returning a data frame which contains the output values only, would also work, provided that the order of rows is maintained.
The functions implementation is shown next:
1def example_evaluation_function(dataFrame): 2 f1 = [] 3 f2 = [] 4 for i in range(len(dataFrame)): 5 row = dataFrame.iloc[i] 6 v = [row.iloc[j] for j in range(len(row))] 7 f1 = function_sphere(v) 8 f2 = function_rosenbrocks(v) 9 return pandas.DataFrame(data={'function_sphere': f1, 'function_restriction': f2})
- Parameters:
dataFrame (DataFrame) – pandas.DataFrame with input values.
- Returns:
pandas.DataFrame containing inputs,
function_sphere()andfunction_restriction()results in new columns.- Return type:
DataFrame
- cvds.Examples.optimization_single_objective_evaluation(dataFrame)
Applies the function
function_sphere()andfunction_restriction()to a data frame.A column with all output values will be added to the data frame. Returning a data frame which contains the output values only, would also work, provided that the order of rows is maintained.
The functions implementation is shown next:
1def example_evaluation_function(dataFrame): 2 f1 = [] 3 f2 = [] 4 for i in range(len(dataFrame)): 5 row = dataFrame.iloc[i] 6 v = [row.iloc[j] for j in range(len(row))] 7 f1.append(function_sphere(v)) 8 f2.append(function_restriction(v)) 9 return pandas.DataFrame(data={'function_sphere': f1, 'function_restriction': f2})
- Parameters:
dataFrame (DataFrame) – pandas.DataFrame with input values.
- Returns:
pandas.DataFrame containing inputs,
function_sphere()andfunction_restriction()results in new columns.- Return type:
DataFrame
cvds.SolutionSpaceOptimizations module
- class cvds.SolutionSpaceOptimizations.SolutionSpaceOptimization
Bases:
objectClass to find an optimal solution space (sub space of the design space containing only valid samples).
- add_input(name, lower_bound=0, upper_bound=1, value=0.5, labels=[])
Add an input variable.
- Parameters:
name (str) – The name of the input variable.
lower_bound (float) – The lower bound for a real valued variables.
upper_bound (float) – The upper bound for a real valued variables.
value (float) – The value. Only used if the variable is not an interval.
labels (List[str]) – The class label set of a class variable.
- add_output(name, lower_crit=-inf, upper_crit=inf, bad_labels=[])
Add an output variable.
- Parameters:
name (str) – The name of the input variable.
lower_crit (float) – The lower critical value for a real valued variables.
upper_crit (float) – The upper critical value for a real valued variables.
bad_labels (List[str]) – The class label set indicating no success of a class variable.
- box_norm_diagonal(box)
A possible quality evaluation function for boxes.
The normalized diagonal is calculated from the normalized box.
- Parameters:
box (Dict[str, List[object]]) – A box. A box is a dictionary {name, [low, up] for real valued variables and a list of class labels for class variables}.
- Returns:
The normalized length of the diagonal.
- Return type:
float
- box_norm_edge_sum(box)
A possible quality evaluation function for boxes.
Here, the sum of all normalized edges is calculated.
- Parameters:
box (Dict[str, List[object]]) – A box. A box is a dictionary {name, [low, up] for real valued variables and a list of class labels for class variables}.
- Returns:
The sum of normalized edges.
- Return type:
float
- box_norm_volume(box)
A possible quality evaluation function for boxes.
The normalized box volume is the product of all relative width of all edges.
- Parameters:
box (Dict[str, List[object]]) – A box. A box is a dictionary {name, [low, up] for real valued variables and a list of class labels for class variables}.
- Returns:
The normalized volume of the box.
- Return type:
float
- box_norm_weighted_edge_sum(box)
A possible quality evaluation function for boxes.
First the normalized edges are sorted by their increasing length. Than, each edges is multiplied by its position and the sum of these values is returned.
- Parameters:
box (Dict[str, List[object]]) – A box. A box is a dictionary {name, [low, up] for real valued variables and a list of class labels for class variables}.
- Returns:
The weighted sum of normalized edges.
- Return type:
float
- check()
Check, if the values set are valid.
- Returns:
List of tuple of (True, if everything is okay, else False / Fail message)
- Return type:
bool
- check_input(name)
Check, if the values of the input variable are valid.
- Parameters:
name (str) – Name of the variable.
- Returns:
Tuple of (True, if everything is okay, else False / Fail message)
- Raises:
CvaException – if no variable is found.
- Return type:
bool
- check_ouput(name)
Check, if the values of a output variable are valid.
- Parameters:
name (str) – Name of the variable.
- Returns:
Tuple of (True, if everything is okay, else False / Fail message)
- Raises:
CvaException – if no variable is found.
- Return type:
bool
- connect(manager=None)
Connect the model to an existing CVA manager.
- Parameters:
manager (cva.Base.Manager) – The CVA manager.
- Raises:
CvaException – if the core operation did not succeed. The exceptions contains the reason.
- estimate_output_ranges(num_samples=1000, apply=True)
Estimate the ranges of real-valued output variables for normalizing.
- Parameters:
num_ssamples – Number of random samples to estimate the ranges.
apply – If apply is True, set the ranges directly, else just return the norm dictionary.
- Returns:
A dictionary {output name, range} as used for
set_output_ranges().- Return type:
Dict[str, float]
- evaluate_sample(input_data, boxes=None)
Takes an existing sample, evaluates all outputs and checks the critical values.
- Parameters:
input_data (DataFrame) – pandas.DataFrame with input columns.
- Returns:
Tuple of (input data, a pandas.DataFrame containing the values for the outputs in combination with the result of calling
test_sample()).- Return type:
Tuple[DataFrame, DataFrame]
- get_history()
Get the optimization history.
- Parameters:
name – Name of the variable.
- Raises:
CvaException – if no history is found.
- Returns:
A dictionary {generation, list of boxes}. A box is a dictionary {name, [low, up] for real valued variables and a list of class labels for class variables}.
- Return type:
Dict[int, List[Dict[str, List[object]]]]
- get_initial_boxes()
Get initial boxes.
- Returns:
List of boxes. A box is a dictionary {name, [low, up] for real valued variables and a list of class labels for class variables}.
- Return type:
List[Dict[str, List[object]]]
- get_initial_qualities()
Get the qualities of pre-defined initial boxes.
- Returns:
List of quality values.
- Return type:
List[float]
- get_input(name)
Get input variable by name.
- Parameters:
name – Name of the variable.
- Raises:
CvaException – if no variable is found.
- Returns:
The input variable.
- Return type:
cva.Structures.CvssInputVariable
- get_input_class_names(name)
Get the attribute names of a class input variable.
- Parameters:
name (str) – Name of the variable.
- Returns:
The attribute names of a class input variable. If the list is empty, the input variable is a real-valued input variable.
- Raises:
CvaException – if no variable is found.
- Return type:
List[str]
- get_input_is_class_names_fixed(name)
Get if the class names of a class-valued input variable are fixed.
- Parameters:
name (str) – Name of the variable.
- Returns:
True if the class names are fixed.
- Raises:
CvaException – if no variable is found.
- Return type:
bool
- get_input_is_interval(name)
Get if the result should be an interval/subset or a single value/class.
- Parameters:
name (str) – Name of the variable.
- Returns:
True, if upper and lower bound / set of class names is used, else for the usage of single value/class names False.
- Raises:
CvaException – if no variable is found.
- Return type:
bool
- get_input_is_lower_fixed(name)
Get if the lower bound is fixed.
- Parameters:
name (str) – Name of the variable.
- Returns:
True, if the bound is fixed, else False.
- Raises:
CvaException – if no variable is found.
- Return type:
bool
- get_input_is_upper_fixed(name)
Get if the upper bound is fixed.
- Parameters:
name (str) – Name of the variable.
- Returns:
True, if the bound is fixed, else False.
- Raises:
CvaException – if no variable is found.
- Return type:
bool
- get_input_is_value_fixed(name)
Get if the single value is fixed (Only used if is_interval = False).
- Parameters:
name (str) – Name of the variable.
- Returns:
True, if the value is fixed, else False.
- Raises:
CvaException – if no variable is found.
- Return type:
bool
- get_input_is_width_fixed(name)
Get if the width is fixed (Only used if is_interval = True).
- Parameters:
name (str) – Name of the variable.
- Returns:
True, if the width is fixed, else False.
- Raises:
CvaException – if no variable is found.
- Return type:
bool
- get_input_lower_bound(name)
Get the lower bound of a real-valued input variable.
- Parameters:
name (str) – Name of the variable.
- Returns:
lower bound of the input variable
- Raises:
CvaException – if no variable is found.
- Return type:
float
- get_input_lower_upper_bound(name)
Get the upper limit for the lower bound (Only used if is_interval = True and is_lower_fixed = False and is_width = False).
The default case moves the lower bound of edge in the design interval. Setting a different bound than the upper design interval bound restricts the lower bound of the edge.
- Parameters:
name (str) – Name of the variable.
- Returns:
The upper bound of the lower bound of the edge or None if not used.
- Return type:
float
- get_input_upper_bound(name)
Get the upper bound of a real-valued input variable.
- Parameters:
name (str) – Name of the variable.
- Returns:
Upper bound of the input variable
- Raises:
CvaException – if no variable is found.
- Return type:
float
- get_input_upper_lower_bound(name)
Get the lower limit for the upper bound (Only used if is_interval = True and is_lower_fixed = False and is_width = False).
The default case moves the upper bound of edge in the design interval. Setting a different bound than the lower design interval bound restricts the upper bound of the edge.
- Parameters:
name (str) – Name of the variable.
- Returns:
The lower bound of the upper bound of the edge or None if not used.
- Return type:
float
- get_input_value(name)
Get the fixed value (Only used if is_interval = False and is_fixed = True).
- Parameters:
name (str) – Name of the variable.
- Returns:
Either a real value or a class depending on the input variable type..
- Raises:
CvaException – if no variable is found.
- Return type:
object
- get_input_width(name)
Gets a fixed width of a real-valued input (only used if is_width = True).
- Parameters:
name (str) – Name of the variable.
- Returns:
The fixed width of the interval.
- Raises:
CvaException – if no variable is found.
- Return type:
float
- get_inputs()
Get input variables.
- Returns:
List of input variables.
- Return type:
List[‘cva.Structures.CvssInputVariable’]
- get_output(name)
Get output variable by name.
- Parameters:
name – Name of the variable.
- Raises:
CvaException – if no variable is found.
- Returns:
The output variable.
- Return type:
cva.Structures.CvssOutputVariable
- get_output_bad_labels(name)
Get the bad labels of a class output variable.
- Parameters:
name (str) – Name of the variable.
- Returns:
The list of bad labels. If the list is empty, the variable is a real-valued variable.
- Raises:
CvaException – if no variable is found.
- Return type:
List[str]
- get_output_crit_low(name)
Get the critical lower bound of an output variable.
- Parameters:
name (str) – Name of the variable.
- Returns:
Critical minimum value as double. Can be NaN.
- Raises:
CvaException – if no variable is found.
- Return type:
float
- get_output_crit_up(name)
Get the critical upper bound of an output variable.
- Parameters:
name (str) – Name of the variable.
- Returns:
Critical maximal value as double. Can be NaN.
- Raises:
CvaException – if no variable is found.
- Return type:
float
- get_output_low_crit_norm(name)
Get the critical lower norm value of an output variable.
- Parameters:
name (str) – Name of the variable.
- Returns:
Norm value.
- Return type:
crit_norm
- Raises:
CvaException – if no variable is found.
- get_output_up_crit_norm(name)
Get the critical upper norm value of an output variable.
- Parameters:
name (str) – Name of the variable.
- Returns:
Norm value.
- Return type:
crit_norm
- Raises:
CvaException – if no variable is found.
- get_outputs()
Get output variables.
- Returns:
List of output variables.
- Return type:
List[‘cva.Structures.CvssOutputVariable’]
- get_parameter(name)
Get an optimization parameter.
- Parameters:
name – The name of the parameter.
- Returns:
The parameter with the given name.
- Return type:
cva.Structures.CvaParameter
- get_parameter_value(name)
Get an optimization parameter value.
- Parameters:
name – The name of the parameter.
- Returns:
The value of the parameter with the given name.
- Return type:
object
- get_parameters()
Get optimization parameters.
- Returns:
Dictionary of parameters used by this optimization.
- Return type:
Dict[str, ‘cva.Structures.CvaParameter’]
- get_result()
Returns the result of an optimization. Raises a CvaException if the result is empty.
- Returns:
A tuple of the result boxes and their qualities. A box is a dictionary {name, [low, up] for real valued variables and a list of class labels for class variables}.
- Return type:
Tuple[List[Dict[str, List[object]]], List[float]]
- init_from(optimization_info)
Copy the parameters from one optimization to this.
- Parameters:
optimization_info (cva.Structures.CvaSolutionSpaceOptimizationInfo) – The optimization parameters.
- optimize(estimate_output_ranges=False, return_crit_changes=False)
Start the optimization.
- Parameters:
estimate_output_ranges (bool) – If set to True,
estimate_output_ranges()with apply=True is called before starting the optimization.return_crit_changes (bool) – If set to True and the best box contains invalid samples, new critical values are calculated so that all samples are valid.
- Raises:
CvaException – if settings are invalid.
- Returns:
Tuple of (list of boxes / List of qualities of the boxes) and a dictionary of new critical values in the case return_crit_changes was True. A box is a dictionary {name, [low, up] for real valued variables and a list of class labels for class variables}.
- Return type:
Tuple[List[Dict[str, List[object]]], List[float], Dict[str, List[object]]]
- position(box)
Use the optimizer to position a fixed box in the design space, so that only a minimum amount of samples is invalid.
- Parameters:
box (Dict[str, List[object]]) – The fixed box. A box is a dictionary {name, [low, up] for real valued variables and a list of class labels for class variables}.
- Raises:
CvaException – if settings are invalid.
- Returns:
Tuple of (list of boxes / List of qualities of the boxes / dictionary of new critical values). A box is a dictionary {name, [low, up] for real valued variables and a list of class labels for class variables}.
- Return type:
Tuple[List[Dict[str, List[object]]], List[float], Dict[str, List[object]]]
- remove_input(name)
Remove input variable by name.
- Parameters:
name (str) – Name of the variable.
- Raises:
CvaException – if no variable is found.
- remove_output(name)
Remove output variable by name.
- Parameters:
name – Name of the variable.
- Raises:
CvaException – if no variable is found.
- sample(variable_names, box, sample_size=100, algorithm='LHS')
Create samples in the given solution space.
- Parameters:
variable_names (List[str]) – List of variables which use the design space for sampling. The rest of the variables is sampled within the box. This can be used to generate scatter charts if a pair of variables is chosen.
box (Dict[str, List[object]]) – A dictionary representing a box as returned by
optimize().sample_size (int) – The number of samples to be created.
algorithm (str) – Can be ‘LHS’, ‘monte-carlo’, ‘space-filling’, ‘FullFactorial’, ‘FractionalFactorial’, ‘FractionalFactorialL3’, ‘DOptimal’, ‘BoxBehnken’ or ‘Sobol’
- Returns:
Tuple of (the generated input data, the output values) as the result of calling
evaluate_sample()).- Return type:
Tuple[DataFrame, DataFrame]
- set_box_evaluation_function(box_evaluation_function)
Set the box evaluation function.
If all samples are good in a box, we need the size as indication of the quality. The default function uses the sum of the normalized edges. You can select from some pre-build functions or define your own quality function. The function needs to accept a dictionary representing the box, like input variable name -> [low, up] and needs to return the size as float.
- Parameters:
box_evaluation_function (Callable[[Dict[str, object]], float]) – A function which access the size of a box.
- set_evaluation_function(evaluation_function)
The evaluation function must accept a pandas.DataFrame as input parameter and return a DateFrame.
The returned pandas.DataFrame must contain all outputs as columns and the same number of rows as the input pandas.DataFrame. It may also contain the input values, so modifying the input data frame is possible. The most simple example for this would be to use the apply-function of a data frame and return its result:
1return input_df.apply(row_function, axis=1).
For every output in this optimization object, the returned data frame has to contain a column with the name of that objective or restriction.
- Parameters:
evaluation_function (Callable[[DataFrame], DataFrame]) – A function with pandas.DataFrame as input and output. (evaluation_function: pandas.DataFrame -> pandas.DataFrame)
- set_initial_boxes(initial_boxes, initial_qualities=[])
Set pre-defined boxes and qualities.
- Parameters:
initial_boxes (Dict[str, List[object]]) – The initial boxes. A box is a dictionary {name, [low, up] for real valued variables and a list of class labels for class variables}.
initial_qualities – The corresponding qualities, if known.If empty, the qualities are calculated automatically.
- set_input_class_names(name, class_names)
Set the attribute names of a class input variable.
- Parameters:
name (str) – Name of the variable.
class_names (List[str]) – The attribute names of a class input variable. If the list is empty, the input variable is a real-valued input variable.
- Raises:
CvaException – if no variable is found.
- set_input_is_class_names_fixed(name, value)
Set if the class names should be fixed(Only used if is_interval = False and if is_value_fixed = False).
- Parameters:
name (str) – Name of the variable.
value (float) – True, if the class names should be fixed.
- set_input_is_interval(name, is_interval)
Set if the result should be an interval/subset or a single value/class.
- Parameters:
name (str) – Name of the variable.
is_interval (bool) – True, if upper and lower bound / set of class names is used, else for the usage of single value/class names False.
- Raises:
CvaException – if no variable is found.
- set_input_is_lower_fixed(name, is_fixed)
Set if the lower bound is fixed.
- Parameters:
name (str) – Name of the variable.
is_fixed (bool) – True, if the bound is fixed, else False.
- Raises:
CvaException – if no variable is found.
- set_input_is_upper_fixed(name, is_fixed)
Set if the upper bound is fixed.
- Parameters:
name (str) – Name of the variable.
is_fixed (bool) – True, if the bound is fixed, else False.
- Raises:
CvaException – if no variable is found.
- set_input_is_value_fixed(name, is_fixed)
Set if the single value is fixed (Only used if is_interval = False).
- Parameters:
name (str) – Name of the variable.
is_fixed (bool) – True, if the value is fixed, else False.
- Raises:
CvaException – if no variable is found.
- set_input_is_width_fixed(name, is_fixed)
Set if the width is fixed (Only used if is_interval = True).
- Parameters:
name (str) – Name of the variable.
is_fixed (bool) – True, if the width is fixed, else False.
- Raises:
CvaException – if no variable is found.
- set_input_lower_bound(name, lower_bound)
Set the lower bound of a real-valued input variable.
- Parameters:
name (str) – Name of the variable.
lower_bound (float) – lower bound of the input variable
- Raises:
CvaException – if no variable is found.
- set_input_lower_upper_bound(name, value)
Set an upper limit for the lower bound (Only used if is_interval = True and is_lower_fixed = False and is_width = False).
The default case moves the lower bound of edge in the design interval. Setting a different bound than the upper design interval bound restricts the lower bound of the edge.
- Parameters:
name (str) – Name of the variable.
value (object) – The upper bound of the lower bound of the edge or None to clear the restriction.
- set_input_upper_bound(name, upper_bound)
Set the upper bound of a real-valued input variable.
- Parameters:
name (str) – Name of the variable.
upper_bound (float) – lower bound of the input variable
- Raises:
CvaException – if no variable is found.
- set_input_upper_lower_bound(name, value)
Set a lower limit for the upper bound (Only used if is_interval = True and is_lower_fixed = False and is_width = False).
The default case moves the upper bound of edge in the design interval. Setting a different bound than the lower design interval bound restricts the upper bound of the edge.
- Parameters:
name (str) – Name of the variable.
value (float) – The lower bound of the upper bound of the edge or None to clear the restriction.
- set_input_value(name, value)
Set the fixed value (Only used if is_interval = False and is_fixed = True).
- Parameters:
name (str) – Name of the variable.
value (object) – Either a real value or a class depending on the input variable type..
- Raises:
CvaException – if no variable is found.
- set_input_width(name, width)
Sets a fixed width of a real-valued input (only used if is_width = True).
- Parameters:
name (str) – Name of the variable.
width – The fixed width of the interval.
- Raises:
CvaException – if no variable is found.
- set_output_bad_labels(name, bad_labels)
Set the bad labels of a class output variable.
- Parameters:
name (str) – Name of the variable.
bad_labels (List[str]) – The list of bad labels. If the list is empty, the variable is a real-valued variable.
- Raises:
CvaException – if no variable is found.
- set_output_crit_low(name, crit_low)
Set the critical lower bound of an output variable.
- Parameters:
name (str) – Name of the variable.
crit_low (float) – Critical minimum value as double. Can be NaN.
- Raises:
CvaException – if no variable is found.
- set_output_crit_up(name, crit_up)
Set the critical upper bound of an output variable.
- Parameters:
name (str) – Name of the variable.
crit_up (float) – Critical maximal value as double. Can be NaN.
- Raises:
CvaException – if no variable is found.
- set_output_low_crit_norm(name, crit_norm)
Set the critical lower norm value of an output variable.
- Parameters:
name (str) – Name of the variable.
crit_norm (float) – Norm value. Must be set and not 0. if crit_low is not NaN.
- Raises:
CvaException – if no variable is found.
- set_output_ranges(norm_dict)
Set ranges for real-valued output variables for normalizing.
- Parameters:
norm_dict (Dict[str, float]) – Dictionary {output name, range)
- set_output_up_crit_norm(name, crit_norm)
Set the critical upper norm value of an output variable.
- Parameters:
name (str) – Name of the variable.
crit_norm (float) – Norm value. Must be set and not 0. if crit_up is not NaN.
- Raises:
CvaException – if no variable is found.
- set_parameter(name, value)
Sets an optimization parameter.
- Parameters:
name (str) – The name of the parameter.
value (object) – The value of the parameter.
- test_sample(evaluated_data)
Checks, if samples are good or bad.
- Parameters:
evaluated_data (DataFrame) – pandas.DataFrame with output columns containing the evaluated data.
- Returns:
pandas.DataFrame with label columns named output variable name + ‘_mark’. The labels are either ‘good’ or ‘bad’ depending on the critical values. A last column ‘overall_mark’ is attached. The label is ‘good’ if all outputs are good else the label is ‘bad’.
- Return type:
DataFrame
- variable_norm_width(variable_name, interval)
Gets the relative width of an interval compared to the design interval of a input variable.
- Parameters:
variable_name (str) – Name of the input variable.
interval (List[float]) – the interval in the form of [lower, upper].
- Returns:
The relative width. If the variable is class variable 1 is returned.
cvds.Structures module
- class cvds.Structures.CvaDesignOfExperimentsInfo
Bases:
objectObjects of this class contain all necessary information to describe a design of experiments task. This includes input variables, restriction functions, and design of experiments parameters.
- get_doe()
Get the created design of experiments as a pandas.DataFrame.
- Returns
The design of experiments or None.
- get_existing_samples()
Get the already existing design of experiments set for a space-filling design.
- Returns:
The existing design of experiment as pandas.DataFrame.
- Return type:
DataFrame
- get_model()
Get the model to be used with an adaptive modeling design.
- Returns:
The CVA model.
- Return type:
cva.Models.Model
- get_models()
Get the models to be used with an adaptive modeling design.
- Returns:
A list of VA models.
- Return type:
List[‘cva.Models.Model’]
- get_parameters()
Get the design of experiment parameters.
- Returns:
The design of experiment parameters.
- Return type:
Dict[str, ‘cva.Structures.CvaParameter’]
- get_restrictions()
Get the list of restrictions.
- Returns:
The list restrictions.
- Return type:
List[‘cva.Structures.CvaRestriction’]
- get_variables()
Get the input variables.
- Returns:
The list input variables.
- Return type:
List[‘cva.Structures.CvaVariable’]
- init_from(info)
Copy from another design of experiments info.
- Parameters:
info (cva.Structures.CvaDesignOfExperimentsInfo) – The info to copy from.
- Returns:
self.
- Return type:
cva.Structures.CvaDesignOfExperimentsInfo
- set_doe(doe)
Set the created design of experiments.
- Parameters:
doe (DataFrame) – A pandas.DataFrame containing the design of experiments.
- set_existing_samples(df)
Set an already existing design of experiments when doing a space-filling design.
- Parameters:
df (DataFrame) – A pandas.DataFrame containing the existing samples.
- set_model(model)
Set a model used for an adaptive modeling design.
- Parameters:
model (cva.Models.Model) – A CVA model.
- set_models(models)
Set models to used for an adaptive modeling design.
- Parameters:
models – A list of CVA models.
- class cvds.Structures.CvaFitTask(c_model_template_paramer=None)
Bases:
objectContainer for CVA task and model parameters.
Task parameters control how the model is fitted including things like cross-validation and hyper-parameter optimization. They are model type independent. The model parameters contain specific information for the chosen model type. This can be the type of a kernel function or the number of neurons of a neural network. Some of these parameters can be optimized, if the optimization is enabled in the task parameters.
Hint
Objects are provided from internal classes and should not be created by the user.
- get_model_parameter_value(name)
Get the value of a model parameter.
- Returns:
The value of the model parameter.
- Return type:
object
- get_model_parameters()
Get model parameter.
- Returns:
Dictionary of model parameters (
cva.Structures.CvaModelParameter).
- get_model_type()
Get the model type.
- Returns:
The model type.
- Return type:
str
- get_task_parameter_value(name)
Get the value of a task parameter.
- Returns:
The value of the task parameter.
- Return type:
object
- get_task_parameters()
Get task parameters. :returns: Dictionary {name, parameter}.
- set_model_parameter_value(name, value)
Set value of a model parameter.
- Parameters:
name (str) – Name of the model parameter.
value (object) – The new value.
- set_model_parameters(model_parameters)
Set model parameters.
- Parameters:
model_parameters (Dict[str, 'cva.Structures.CvaModelParameter']) – Dictionary {name, model parameter}.
- set_task_parameter_value(name, value)
Set value of a task parameter.
- Parameters:
name (str) – Name of the task parameter.
value (object) – The new value.
- set_task_parameters(task_parameters)
Set task parameters.
- Parameters:
task_parameters (Dict[str, 'cva.Structures.CvaTaskParameter']) – Dictionary {name, model parameter}.
- property model_type: str
The model type.
- Getter:
Return the model type.
- class cvds.Structures.CvaFunction(name)
Bases:
objectBase class for objective and restriction functions.
- Parameters:
name – Name of the restriction.
- get_name()
Names of functions, restrictions, and variables have to be unique identifiers.
- Returns:
The name of the function object.
- Return type:
str
- property name: str
Names of functions, restrictions, and variables have to be unique identifiers.
- Getter:
Returns the name of the function object.
- class cvds.Structures.CvaModelCompare(c_model_compare, models)
Bases:
objectComparison class for models with the same input variables and the same output variable.
Hint
Objects are provided from internal classes and should not be created by the user.
- get_matrix()
Get the comparison matrix.
- Returns:
A matrix for pairwise comparison. A -1 means row lost against column, 0 no significant difference, 1 row won against column.
- Return type:
DataFrame
- get_winner()
Get the winner model.
- Returns:
The best model of the comparison.
- Return type:
cva.Models.Model
- get_wins()
Get how many times a model won against other models.
- Returns:
A list of how many times a model won against others.
- Return type:
List[Tuple[‘cva.Models.Model’, int]]
- class cvds.Structures.CvaModelInfo(c_model_info, fit_task, input_names, output_name, output_class_names, original_output_values, model_type)
Bases:
objectCVA model information containing learn parameters (
cva.Structures.CvaFitTask()) and if successfully fitted, qualities, variable importance and sensitivity values.Hint
Objects are provided from internal classes and should not be created by the user.
Qualities
The model qualities can be accessed with the function
get_qualities(). The qualities are returned in form of a pandas.DataFrame with the following structure:Index
output
model_type
mean_squared_error
…
…
Final
y
neural_network
9.12
…
…
Validation
y
neural_network
12.34
…
…
The final values are the quality values of the model fitted on all data using the optimized hyper-parameters. The validation values are the mean qualities on the validation parts.
Variable importance
The importance of the variables can be accessed with the function
get_variable_importance(). The importance values are returned in form of a data frame with the following structure:Input
output
model_type
quality
ranking
x1
y
neural_network
15.67
1.0
x2
y
neural_network
14.56
0.2
…
y
neural_network
…
…
One row exists for each input variable. The quality columns shows the mean squared error of the model after removing the variable. The ranking value shows the importance in comparison with the other variables. A one means, that after removing this variable, the quality drops most. Thus, this variable is most important. The other ranking values relate to their quality value to the quality value of the most important variable. Sometimes the ranking can be negative. This indicates, that removing the variable actually improves the model. Thus, the quality value is lower than the final quality value. The ranking works like before, only the least important variable is the base line for the negative ranking.
Variable sensitivity
The sensitivity of the variables can be accessed with the function
get_variable_sensitivity(). The sensitivity values are returned in form of a data frame with the following structure:Input
output
model_type
sobol_index
total_sobol_index
x1
y
neural_network
0.89
0.84
x2
y
neural_network
0.11
0.16
…
y
neural_network
…
…
One row exists for each input variable. The sensitivity is measured using the Sobol indices.
Validation values
The validation values can be accessed with the function
get_validation_data_frame(). The validation values are returned in form of a data frame with the following structure depending on the output variable type:Real-valued output variable
Index
output
model_type
original_value
predicted_value
0
y
neural_network
626.468
557.014
1
y
neural_network
126.126
122.262
…
y
neural_network
…
…
The index is the index of the learn data points. The predictions are from the validation parts. Thus, you can plot for example the original values against the predicted values to visualize the validation model quality.
Class output variable
Index
output
model_type
original_value
predicted_value
0
y
neural_network
A
B
1
y
neural_network
C
C
…
y
neural_network
…
…
The index is the index of the learn data points. The predictions are from the validation parts. Thus, you can use this to create a confusion matrix (
get_confusion_matrix()) for the validation part.Confusion matrix
For classification models a confusion matrix (
get_confusion_matrix()) can be generated.Index
orig_A
orig_B
…
pred_A
25
1
…
pred_B
2
37
…
…
…
…
…
- get_confusion_matrix(df=None, class_names=None)
Create a confusion matrix.
- Parameters:
df (DataFrame) – A data frame with a column “original_values” and a column “predicted_values”. If no data frame is given, the validation data frame is used.
- Raises:
CvaException – if the model is not a classifier or one of the needed columns is missing.
- Returns:
A data frame containing the confusion matrix.
- get_fit_task()
Get the fit task used to fit the model.
- Returns:
The fit task containing the parameters used to fit the model.
- Return type:
cva.Structures.CvaFitTask
- get_invalid_reason()
If the model is not valid, get the reason or ‘’ if the model is valid.
- Returns:
The reason for failure.
- Return type:
str
- get_is_valid()
Check, if the model is valid.
- Returns:
True, if the model has been successfully fitted, else False.
- Return type:
bool
- get_model_type()
Get the model type.
- Returns:
The model type.
- Return type:
str
- get_morris()
Get the sensitivity in form of the Morris indices (see CvaModelInfo). :returns: A data frame with the sensitivity for the input variables (Mean and standard deviation of the morris function).
- get_qualities()
Get the quality data frame (see
CvaModelInfo).- Returns:
The quality data frame.
- Return type:
DataFrame
- get_validation_data_frame()
Get the data frame with comparison between original and predicted values for the internal validation (see
CvaModelInfo).- Returns:
Data frame with the comparison.
- Return type:
DataFrame
- get_variable_importance()
Get the variable importance data frame (see
CvaModelInfo).- Returns:
A pandas.DataFrame with the input variable importance.
- Return type:
DataFrame
- get_variable_sensitivity()
Get the sensitivity in form of the Sobol indices (see
CvaModelInfo).- Returns:
A data frame with the sensitivity for the input variables (Sobol index and total Sobol index).
- Return type:
DataFrame
- class cvds.Structures.CvaModelParameter(name, value, value_type, enums=[], description='', is_optimizable=False, opt_min=nan, opt_max=nan, is_core=True)
Bases:
CvaParameterCVA modeling parameter extending the normal parameters by is optimizable and optimization limits.
- Parameters:
name (str) – Name of the parameter.
value (object) – Default value of the parameter.
value_type (str) – Value type of the parameter (“integer”, “float”, “boolean”, “enum”, “string”).
enums (List[str]) – List of names, if the value type is “enum”.
description (str) – Short description of the parameter.
is_optimizable (bool) – If true, this is a hyperparameter which is optimized, else it is a configurable parameter.
opt_min (float) – If this is a hyperparameter, this is the lower limit (only needed for value_type float and integer).
opt_max (float) – If this is a hyperparameter, this is the upper limit (only needed for value_type float and integer).
- get_is_optimizable()
Check, if the parameter is optimizable.
- Returns:
True, if the parameter is optimizable, else False.
- Return type:
bool
- get_opt_max()
Get the upper bound of the optimization range.
- Raises:
CvaException – if the parameter is not optimizable.
- Returns:
The upper bound.
- Return type:
float
- get_opt_min()
Get the lower bound of the optimization range.
- Raises:
CvaException – if the parameter is not optimizable.
- Returns:
The lower bound.
- Return type:
float
- init_from(parameter)
Copy from a parameter.
- Parameters:
parameter (cva.Structures.CvaModelParameter) – The parameter to copy from.
- Returns:
self.
- Return type:
- to_dict()
Convert the parameter to a dictionary.
- Returns:
Dictionary {name, value}
- Return type:
Dict[str, object]
- property opt_max: float
The upper bound of the optimization range.
- Getter:
Returns the upper bound of the optimization range.
- property opt_min: float
The lower bound of the optimization range.
- Getter:
Returns the lower bound of the optimization range.
- class cvds.Structures.CvaObjective(name, obj_type='Minimize', obj_value=0.0)
Bases:
CvaFunctionWrapper class for objective functions.
- Parameters:
name – Name of the function, also used as column name for data frames. Has to be unique.
obj_type – Type of the objective function, ‘Minimize’ (default), ‘Maximize’, ‘Value’
obj_value – A target value for this objective.
- get_type()
The type defines the direction of the optimization. It can be ‘Minimize’, ‘Maximize’, or ‘Value’. In case of ‘Value’ a target value has to be set. These types are just for convenience, since every type can be changed into a minimization task. Default is ‘Minimize’. ‘Maximize’ and ‘Value’ can also implemented within the evaluation function of the optimization, e.g. using \(1/fitness\) or \((fitness-x)^2\) as fitness values and minimizing these transformed values.
- Returns:
The type (‘direction’) of this objective.
- Return type:
str
- get_value()
This will be used, if type is set to ‘Value’. Solutions for this objective are considered to be better when closer to the target value.
- Returns:
The target value of this objective.
- Return type:
float
- init_from(objective)
Copy from objective.
- Parameters:
objective (cva.Structures.CvaObjective) – The objective to copy from.
- Returns:
self.
- Return type:
cva.Structures.CvaObjective
- property type: str
The type defines the direction of the optimization. It can be ‘Minimize’, ‘Maximize’, or ‘Value’. In case of ‘Value’ a target value has to be set. These types are just for convenience, since every type can be changed into a minimization task. Default is ‘Minimize’. ‘Maximize’ and ‘Value’ can also implemented within the evaluation function of the optimization, e.g. using \(1/fitness\) or \((fitness-x)^2\) as fitness values and minimizing these transformed values.
- Getter:
Returns the type (‘direction’) of this objective.
- property value: float
This will be used, if type is set to ‘Value’. Solutions for this objective are considered to be better when closer to the target value.
- Getter:
Returns the target value of this objective.
- class cvds.Structures.CvaOptimizationInfo
Bases:
objectObjects of this class contain all necessary information to describe an optimization task. This includes input variables, objective functions, restriction functions, and optimization parameters.
- get_generations()
Returns the maximum number of generations.
- Returns:
Number of optimization loop iterations.
- Return type:
int
- get_objectives()
The list of objective function objects.
- Returns:
List of objectives.
- Return type:
List[‘cva.Structures.CvaObjective’]
- get_parameters()
Get the parameters.
- Returns:
Dictionary {name, parameter}`.
- Return type:
Dict[str, ‘cva.Structures.CvaParameter’]
- get_restrictions()
The list of restriction function objects.
- Returns:
List of restrictions.
- Return type:
List[‘cva.Structures.CvaRestriction’]
- get_variables()
The list of input variable objects.
- Returns:
List variables.
- Return type:
List[‘cva.Structures.CvaVariable’]
- init_from(info)
Copy from another optimization info.
- Parameters:
info (cva.Structures.CvaOptimizationInfo) – The info to copy from.
- Returns:
self.
- Return type:
cva.Structures.CvaOptimizationInfo
- set_generations(generations)
Sets the maximum number of generations to be performed by an optimization task.
- Parameters:
generations (int) – Maximum number of optimization loop iterations.
- set_parameters(parameters)
Set the optimization parameters.
- Parameters:
parameters (Dict[str, 'cva.Structures.CvaParameter']) – Dictionary {name, parameter}.
- class cvds.Structures.CvaParallelTask(model, input_variable_names, output_variable_name, df, check_path, check_type)
Bases:
objectStructure containing information for a modeling task. This structure is intended to be used with the parallel interface.
- Parameters:
model (cva.Models.Model) – The model (cva.Models.Model) created by the manager.
input_variable_names (List[str]) – The input variable names.
output_variable_name (str) – The output variable name.
df (pandas.DataFrame) – A pandas data frame with learn data.
check_path (str) – If a path is given, the models for each task a stored there as a check point. This implies, that the path is reachable from all clients. The name of the files is composed if the output variable name and the model type.
check_type (str) – The check type can be pickle or xml. It is used when a check path is given and determines the type of file stored after completing a task.
- check_path
If a path is given, the models for each task a stored there as a check point. This implies, that the path is reachable from all clients. The name of the files is composed if the output variable name and the model type.
- check_type
The check type can be pickle or xml. It is used when a check path is given and determines the type of file stored after completing a task.
- df
A pandas data frame with learn data.
- input_variable_names
The input variable names.
- model
The model (
cva.Models.Model) created by the manager.
- output_variable_name
The output variable name.
- class cvds.Structures.CvaParameter(name, value, value_type, enums=[], description='', core=True)
Bases:
objectCVA parameter including name, description, value and value type.
- Parameters:
name (str) – Name of the parameter.
value (object) – Default value of the parameter.
value_type (str) – Value type of the parameter (“integer”, “float”, “boolean”, “enum”, “string”).
enums (List[str]) – List of names, if the value type is “enum”.
description (str) – Short description of the parameter.
- get_description()
Get additional description on the parameter.
- Returns:
Additional description, if available.
- Return type:
str
- get_enums()
Get the names of an enum parameter.
- Returns:
A list of possible name of the enum parameter.
- Raises:
CvaException – if the parameter is not an enum parameter.
- Return type:
List[str]
- get_name()
Get the name of the parameter.
- Returns:
The name of the parameter.
- Return type:
str
- get_value()
Get the current value of the parameter.
- Returns:
The value.
- Return type:
object
- get_value_type()
Get the value type.
- Returns:
The value type.
- Return type:
str
- init_from(parameter)
Copy from a parameter.
- Parameters:
parameter (cva.Structures.CvaParameter) – The parameter to copy from.
- Returns:
self.
- Return type:
- is_core_parameter()
Check the internal flag.
- Returns:
True if this parameter should be set in CVA-core.
- Return type:
bool
- set_value(value)
Set a new value for the parameter.
- Parameters:
value (object) – The value must be of the same type as stated in value_type.
- Raises:
CvaException – if the type does not fit or an unknown name for an enum is given.
- to_string()
Convert value to string.
- Returns:
The value as a string.
- Return type:
str
- property description: str
Additional description on the parameter.
- Getter:
Returns additional description on the parameter.
- property enums: List[str]
The names of an enum parameter.
- Getter:
Returns the names of an enum parameter.
- property name: str
The name of the parameter.
- Getter:
Returns the name of the parameter.
- property value: object
The current value of the parameter.
- Getter:
Returns current value of the parameter.
- Setter:
Sets current value of the parameter.
- Type:
object
- property value_type: str
The value type.
- Getter:
Returns the value type.
- class cvds.Structures.CvaRestriction(name, cmp, crit)
Bases:
CvaFunctionWrapper class for restriction functions.
Adding a restriction to an optimization with
1add_restriction('res', '<', 5.0)
has the following consequences: First of all, the evaluation function has to provide a column called ‘res’ within the resulting data frame. The restriction function and the evaluation function have to be implemented by the user. Only the individuals with an column entry ‘< 5.0’ are considered as valid solutions.
- Parameters:
name – The name of this restriction function. Has to be unique.
cmp – The comparator, has to be one of ‘<’,’<=’,’>=’,’>’
crit – The critical value - depending on selected comparator this is either a lower bound or an upper bound.
- check(values)
Check values if they fulfill the restriction.
- Parameters:
values (List[float]) – Values to be checked.
- Returns:
A list of booleans. True if the check is passed else False.
- Return type:
List[bool]
- distance(values)
Calculate the distances to the critical value.
- Parameters:
values (List[float]) – Values to be checked.
- Returns:
A list of booleans. True if the check is passed else False.
- Return type:
List[float]
- get_comparator()
Get the comparator.
- Returns:
The comparator as string.
- Return type:
str
- get_value()
Get the critical value.
- Returns:
The critical value.
- Return type:
float
- init_from(restriction)
Copy from restriction.
- Parameters:
restriction (cva.Structures.CvaRestriction) – The restriction to copy from.
- Returns:
self.
- Return type:
cva.Structures.CvaRestriction
- property comparator: str
the comparator.
- Getter:
Returns the comparator as string.
- property value: float
The critical value.
- Getter:
Returns the critical value.
- class cvds.Structures.CvaSolutionSpaceOptimizationInfo
Bases:
objectObjects of this class contain all necessary information to describe a solution space optimization task. This includes input variables, output variables, start boxes, and optimization parameters.
- get_parameters()
Get the optimization parameter.
- Returns:
Dictionary {name, parameter}
- Return type:
Dict[str, ‘cva.Structures.CvaParameter’]
- init_from(info)
Copy from another optimization info.
- Parameters:
info (cva.Structures.CvaSolutionSpaceOptimizationInfo) – The info to copy from.
- Returns:
self.
- Return type:
cva.Structures.CvaSolutionSpaceOptimizationInfo
- initial_boxes
start value(s). Depending on the type it could be a tuple of (min, max) or a list of class names.
- Type:
List of start boxes. A box is a dictionary of variable name
- initial_qualities
List of qualities corresponding with the start boxes.
- input_variables
List of CvssInputVariable describing the input variables
- output_variables
List of CvssOutputVariable describing the output variables
- parameters
Dictionary of optimization parameters.
- class cvds.Structures.CvaTaskParameter(name, value, value_type, enums=[], description='', core=True)
Bases:
CvaParameterCVA task parameter extending normal parameters.
Hint
Objects are provided from internal classes and should not be created by the user.
- init_from(parameter)
Copy from a parameter.
- Parameters:
parameter (cva.Structures.CvaTaskParameter) – The parameter to copy from.
- Returns:
self.
- Return type:
- class cvds.Structures.CvaVariable(c_variable=None)
Bases:
objectWrapper for variables.
Hint
Objects are provided from internal classes and should not be created by the user.
- Parameters:
c_variable – Only used internally.
- get_class_names()
Get the attribute names of a class variable.
- Returns:
The attribute names of a class variable. If the list is empty, the variable is a real-valued variable.
- Return type:
List[str]
- get_lower_bound()
Get the valid minimum value of a variable.
- Returns:
Minimum value.
- Return type:
float
- get_metric_values()
Get the values of a metric variable.
- Returns:
The values of a metric variable.
- Return type:
List[str]
- get_name()
Get the name of the variable.
- Returns:
Name of the variable.
- Return type:
str
- get_type()
Get the type of a variable (class, metric or real).
- Returns:
The type of the variable.
- Return type:
str
- get_upper_bound()
Get the valid maximum value of a variable.
- Returns:
Maximum value.
- Return type:
float
- init_from(variable)
Copy from a variable.
- Parameters:
variable (cva.Structures.CvaVariable) – The parameter to copy from.
- Returns:
self.
- Return type:
- set_properties(name, lower_bound=0.0, upper_bound=0.0, vartype='real', class_names=[], metric_values=[])
Set the properties of a variable.
- Parameters:
name (str) – Name of the variable.
minimum – Minimum value
maximum – Maximum value
vartype (str) – Type can be real, metric or class
class_names (List[str]) – List of names (set of valid values) for a nominal variable.
metric_values (List[str]) – List of values (set of valid values) for a nominal variable.
- property class_names: List[str]
The attribute names of a class variable.
- Getter:
Returns the attribute names of a class variable.
- property lower_bound: float
The valid minimum value of a variable.
- Getter:
Returns the valid minimum value of a variable.
- property metric_values: List[str]
The values of a metric variable.
- Getter:
Returns the values of a metric variable.
- property name: str
The name of the variable.
- Getter:
Returns the name of the variable.
- property type: str
The type of a variable (class, metric or real).
- Getter:
Returns the type of a variable (class, metric or real).
- property upper_bound: float
The valid maximum value of a variable.
- Getter:
Returns the valid maximum value of a variable.
- class cvds.Structures.CvssInputVariable
Bases:
objectWrapper for solution space input variables.
An input variable describes one edge of the design space. It can be either real-valued or a list of class names. A typical task is to find either the largest interval (real-valued) or the biggest subset of the class names while all samples within the box are good samples. An input variable can constrained.
real-valued: The lower or upper bound or the width of the interval can be fixed. Instead of optimizing an interval, the variable can be set to only find one good value. If both bounds are fixed or the single value is fixed, the variable is not considered in the optimization.
class: Instead of finding a subset the task can be changed to find one good class. If the set of classes or a single class is fixed, the variable is not considered in the optimization
- check()
Check, if the values set are valid.
- Returns:
Tuple of (True, if everything is okay, else False / Fail message).
- Return type:
Tuple[bool, str]
- get_class_names()
Get the attribute names of a class variable.
- Returns:
The attribute names of a class variable. If the list is empty, the variable is a real-valued variable.
- Return type:
List[str]
- get_is_class_names_fixed()
Get if the class labels are fixed.
- Returns:
True, if the class labels are fixed, else False.
- Return type:
bool
- get_is_interval()
Get if the result should be an interval/subset or a single value/class.
- Returns:
True, if upper and lower bound / set of class names is used, else for the usage of single value/class names False.
- Return type:
bool
- get_is_lower_fixed()
Get if the lower bound is fixed.
- Returns:
True, if the bound is fixed, else False.
- Return type:
bool
- get_is_upper_fixed()
Get if the upper bound is fixed.
- Returns:
True, if the bound is fixed, else False.
- Return type:
bool
- get_is_value_fixed()
Get if the single value is fixed (Only used if is_interval = False).
- Returns:
True, if the value is fixed, else False.
- Return type:
bool
- get_is_width_fixed()
Get if the width is fixed (Only used if is_interval = True).
- Returns:
True, if the width is fixed, else False.
- Return type:
bool
- get_lower_bound()
Get the lower bound of a real-valued variable.
- Returns:
lower bound of the variable.
- Return type:
float
- get_lower_upper_bound()
Get the upper limit for the lower bound (Only used if is_interval = True and is_lower_fixed = False and is_width = False).
The default case moves the lower bound of edge in the design interval. Setting a different bound than the upper design interval bound restricts the lower bound of the edge.
- Returns:
The upper bound of the lower bound of the edge or None if not used.
- Return type:
float
- get_name()
Get the name of the variable.
- Returns:
Name of the variable.
- Return type:
str
- get_type()
Get the type of a variable (class or real).
- Returns:
Variable type as string
- Return type:
str
- get_upper_bound()
Get the upper bound of a real-valued variable.
- Returns:
Upper bound of the variable.
- Return type:
float
- get_upper_lower_bound()
Get the lower limit for the upper bound (Only used if is_interval = True and is_lower_fixed = False and is_width = False).
The default case moves the upper bound of edge in the design interval. Setting a different bound than the lower design interval bound restricts the upper bound of the edge.
- Returns:
The lower bound of the upper bound of the edge or None if not used.
- Return type:
float
- get_value()
Get the fixed value (Only used if is_interval = False and is_fixed = True).
- Returns:
Either a real value or a class depending on the variable type..
- Return type:
object
- get_width()
Gets a fixed width of a real-valued input (only used if is_width = True).
- Returns:
The fixed width of the interval.
- Return type:
float
- init_from(variable)
Copy from another input.
- Parameters:
variable (cva.Structures.CvssInputVariable) – The variable to copy from.
- Returns:
self.
- Return type:
cva.Structures.CvssInputVariable
- set_class_names(class_names)
Set the attribute names of a class variable.
- Parameters:
class_names (List[str]) – The attribute names of a class variable. If the list is empty, the variable is a real-valued variable.
- set_is_class_names_fixed(is_fixed)
Set if the class labels are fixed.
- Parameters:
is_fixed (bool) – True, if the class labels are fixed, else False.
- set_is_interval(is_interval)
Set if the result should be an interval/subset or a single value/class.
- Parameters:
is_interval (bool) – True, if upper and lower bound / set of class names is used, else for the usage of single value/class names False.
- set_is_lower_fixed(is_fixed)
Set if the lower bound is fixed.
- Parameters:
is_fixed (bool) – True, if the bound is fixed, else False.
- set_is_upper_fixed(is_fixed)
Set if the upper bound is fixed.
- Parameters:
is_fixed (bool) – True, if the bound is fixed, else False.
- set_is_value_fixed(is_fixed)
Set if the single value is fixed (Only used if is_interval = False).
- Parameters:
is_fixed (bool) – True, if the value is fixed, else False.
- set_is_width_fixed(is_fixed)
Set if the width is fixed (Only used if is_interval = True).
- Parameters:
is_fixed (bool) – True, if the width is fixed, else False.
- set_lower_bound(lower_bound)
Set the lower bound of a real-valued variable.
- Parameters:
lower_bound (float) – lower bound of the variable.
- set_lower_upper_bound(value)
Set an upper limit for the lower bound (Only used if is_interval = True and is_lower_fixed = False and is_width = False).
The default case moves the lower bound of edge in the design interval. Setting a different bound than the upper design interval bound restricts the lower bound of the edge.
- Parameters:
value (float) – The upper bound of the lower bound of the edge or None to clear the restriction.
- set_properties(name, lower_bound=0.0, upper_bound=0.0, value=0.5, vartype='real', class_names=[])
Set the essential properties of an input variable.
- Parameters:
name (str) – Name of the variable.
lower_bound (float) – Lower design space bound.
upper_bound (float) – Upper design space bound.
value (float) – The value is needed if the input variable should be fixed at a certain value or class name.
vartype (str) – Type can be real, metric (same as real), or class
class_names (List[str]) – List of names (set of valid values) for a nominal variable.
- set_upper_bound(upper_bound)
Set the upper bound of a real-valued variable.
- Parameters:
upper_bound (float) – Upper bound of the variable.
- set_upper_lower_bound(value)
Set a lower limit for the upper bound (Only used if is_interval = True and is_lower_fixed = False and is_width = False).
The default case moves the upper bound of edge in the design interval. Setting a different bound than the lower design interval bound restricts the upper bound of the edge.
- Parameters:
value (float) – The lower bound of the upper bound of the edge or None to clear the restriction.
- set_value(value)
Set the fixed value (Only used if is_interval = False and is_fixed = True).
- Parameters:
value (object) – Either a real value or a class depending on the variable type.
- set_width(width)
Sets a fixed width of a real-valued input (only used if is_width = True).
- Parameters:
width (float) – The fixed width of the interval.
- property name: str
The name of the parameter.
- Getter:
Returns the name of the parameter.
- property type: str
The type of a variable (class, metric or real).
- Getter:
Returns the type of a variable (class, metric or real).
- class cvds.Structures.CvssOutputVariable
Bases:
objectWrapper for solution space output variables. The output variables decide if a sample (design) is good or bad. Each output variable has either critical values (real-valued) or bad labels (class names of a classifier).
- check()
Check, if the values set are valid.
- Returns:
Tuple of (True, if everything is okay, else False / Fail message).
- Return type:
Tuple[bool, str]
- get_bad_labels()
Get the bad labels of a class output variable.
- Returns:
The list of bad labels. If the list is empty, the variable is a real-valued variable.
- Return type:
List[str]
- get_crit_low()
Get the critical lower bound of an output variable.
- Returns:
Critical minimum value as double. Can be NaN.
- Return type:
float
- get_crit_up()
Get the critical upper bound of an output variable.
- Returns:
Critical maximal value as double. Can be NaN.
- Return type:
float
- get_low_crit_norm()
Get the critical lower norm value of an output variable.
- Returns:
Norm value.
- Return type:
crit_norm
- get_name()
Get the name of the variable.
- Returns:
Name of the variable.
- Return type:
str
- get_type()
Get the type of a variable (class or real).
- Returns:
Variable type as string.
- Return type:
str
- get_up_crit_norm()
Get the critical upper norm value of an output variable.
- Returns:
Norm value.
- Return type:
crit_norm
- init_from(variable)
Copy from another output.
- Parameters:
variable (cva.Structures.CvssOutputVariable) – The variable to copy from.
- Returns:
self.
- Return type:
cva.Structures.CvssOutputVariable
- set_bad_labels(bad_labels)
Set the bad labels of a class output variable.
- Parameters:
bad_labels (List[str]) – The list of bad labels. If the list is empty, the variable is a real-valued variable.
- set_crit_low(crit_low)
Set the critical lower bound of an output variable.
- Parameters:
crit_low (float) – Critical minimum value as double. Can be NaN.
- set_crit_up(crit_up)
Set the critical upper bound of an output variable.
- Parameters:
crit_up (float) – Critical maximal value as double. Can be NaN.
- set_low_crit_norm(crit_norm)
Set the critical lower norm value of an output variable.
- Parameters:
crit_norm (float) – Norm value. Must be set and not 0. if crit_low is not NaN.
- set_properties(name, crit_low=nan, crit_up=nan, vartype='real', bad_labels=[])
Set the essential properties of an output variable.
- Parameters:
name (str) – Name of the variable.
crit_low (float) – Minimum value
crit_up (float) – Maximum value
vartype (str) – Type can be real, metric (same as real), or class
bad_labels (List[str]) – List of names (set of valid values) for a nominal variable.
- set_up_crit_norm(crit_norm)
Set the critical upper norm value of an output variable.
- Parameters:
crit_norm (float) – Norm value. Must be set and not 0. if crit_up is not NaN.
- property name: str
The name of the parameter.
- Getter:
Returns the name of the parameter.
- property type: str
The type of a variable (class, metric or real).
- Getter:
Returns the type of a variable (class, metric or real).
- cvds.Structures.create_default_doe_parameter()
Create common design of experiments parameter with default values.
- Returns:
Dictionary {name, default parameter}.
- Return type:
Dict[str, ‘cva.Structures.CvaParameter’]
- cvds.Structures.create_default_optimization_parameter()
Create common optimization parameter with default values.
- Returns:
Dictionary of default parameter.
- Return type:
Dict[str, ‘cva.Structures.CvaParameter’]
- cvds.Structures.create_default_solution_space_optimization_parameter()
Create common optimization parameter with default values.
- Returns:
Dictionary of default parameter.
- Return type:
Dict[str, ‘cva.Structures.CvaParameter’]
- cvds.Structures.create_default_task_parameters()
Create common task parameters with default values.
- Returns:
Dictionary {name, parameter} of default parameter.
- Return type:
Dict[str, ‘cva.Structures.CvaTaskParameter’]
- cvds.Structures.create_task(manager, model_type)
Create task and model parameters with default values for a specific model type.
- Parameters:
manager – The CVA manager object.
model_type – The model type (one of
cva.Base.Manager.available_model_types()).
- Raises:
CvaException – if the model type is not recognized.