cva package

cva.Base module

This module contains basic classes and functions.

class cva.Base.Manager(*args, **kwargs)

Bases: BaseManager

Class to connect to the CVA 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.

available_model_types()

Get the list of available model types.

compare_models(models)

Compare matching models.

For each group of matching models (same input variables and same output variable) a comparison is performed. The results for one group contains the winner (best model), a list of how many times a model won against another and a matrix for pairwise comparison. A -1 means row lost against column, 0 no significant difference, 1 row won against column.

Parameters:

models – List of models to compare.

Returns:

A list of comparison results (see cva.Structures.CvaModelCompare).

create_design_of_experiments()

Create a new design of experiments object.

Returns:

New design of experiments object.

create_ensemble_model(models, predict_mode='mean_predict')

Create an ensemble model grouping a set of models.

All models must have been fitted before and must be valid. Also, all models must have the same input variable set and the same output variable.

Parameters:
  • models – A list of trained and valid models.

  • predict_mode – The mode of prediction. Possible values: mean_predict, mean_weighted_predict, mean_exp_weighted_predict, best_predict. Default value is mean_predict.

Returns:

The ensemble model.

create_model(model_type)

Create an empty model of the given type.

Parameters:

model_type – One of the available model types (get list with available_model_types()).

Returns:

Model with default model and task parameters.

create_optimization()

Create a new optimization object.

Returns:

New optimization object.

create_parallel_tasks(model_names, input_variable_names, output_variable_names, df, check_path=None, check_type='pickle')

Create wrapper structures for fit task used for parallelization.

Parameters:
  • model_names – Model name types (one of cva.Base.Manager.available_model_types()).

  • input_variable_names – Input variable names.

  • output_variable_names – Output variable names.

  • df – pandas.DataFrame with learn data.

  • 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.

Returns:

A list of task wrappers (cva.Structures.CvaParallelTask).

create_solution_space_optimizer()

Create a new solution space optimizer and return it.

Returns:

The new solution space optimizer.

create_user_model(user_model)

Create a user model.

Parameters:

user_model – Wrapper object for the user implementation of a modeling algorithm.

Returns:

Model with a user implementation of a modeling algorithm.

Raises:

CvaException – if the pickle does not contain a single model.

exit()

Disconnect from core and release license

import_model(model_file)

Import a model from disk using the CVA xml format.

Parameters:

model_file – The name of the model file.

Returns:

Model created from the CVA xml export file.

init()

Reconnect to core and block license

load_design_of_experiments(pickle_file)

Load a design of experiments from a pickle file.

Parameters:

pickle_file – The name of the pickle file

Returns:

The unpickled design of experiments.

Raises:

CvaException – if the pickle could not be loaded.

load_model(pickle_file)

Load a model from a pickle file.

Parameters:

pickle_file – The name of the pickle file.

Returns:

The unpickled model.

Raises:

CvaException – if the pickle does not contain a single model.

load_optimization(pickle_file)

Load an optimization from a pickle file.

Parameters:

pickle_file – The name of the pickle file.

Returns:

The unpickled optimization.

Raises:

CvaException – if the pickle could not be loaded.

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.

start_model_service(flask_port=5000)

Start a flask service enabling the usage of user models.

Parameters:

flask_port – The port for the flask service. The default is 5000.

Raises:

CvaException – if flask not found.

stop_model_service()
class cva.Base.PredictManager(*args, **kwargs)

Bases: InternalPredictManager

Class to connect to the CVA C++ core and use the predict capability of models.

Hint

Models connected to a predict manager can only use the predict function, but do not require a connection a license manager.

import_model(model_file)

Import a model from disk using the CVA xml format.

Parameters:

model_file – The name of the model file.

Returns:

Model created from the CVA xml export file.

load_model(pickle_file)

Load a model from a pickle file.

Parameters:

pickle_file – The name of the pickle file

Returns:

The unpickled model.

Raises:

CvaException – if the pickle does not contain a single model.

cva.Base.html_help()

Open the html help in the default browser

cva.Base.parallel_fit(parallel_task)

Callback function for parallel fitting models.

This callback function can be used to fit models in parallel. The code shows how to use this for example with joblib. First initialize with the Rosenbrock example.

1from cva import Base, Examples
2from joblib import Parallel, delayed
3
4manager = Base.Manager()
5model_types = manager.available_model_types()
6
7example = Examples.example_rosenbrock()
8input_variable_names = example['input_variable_names']
9output_variable_name = example['output_variable_names'][0]

Next, you create the modeling tasks.

1model_tasks = manager.create_parallel_tasks(model_types, input_variable_names, [output_variable_name], example['df'])

You need to adjust a parameter for the Rosenbrock example.

1model = [t.model for t in model_tasks if t.model.get_model_type()=='random_forest'][0]
2model.get_fit_task().get_model_parameters()['mtry'].set_value(2)

Now use this the joblib parallel. You need to use multi-processing not multi-threading.

1models = Parallel(n_jobs=4)(delayed(Base.parallel_fit)(t) for t in model_tasks)
2[m.connect(manager) for m in models]

Note, that you need to connect the models after fitting to a manager to use them.

Parameters:

parallel_task – Information needed to fit a model. Must be of type cva.Structures.CvaParallelTask and is best created with create_parallel_tasks().

cva.Base.parallel_predict(models, df)

Callback function for parallel model predictions.

This callback function can be used to predict in parallel. The code shows how to use this for example with joblib.

Parameters:
  • models – List of successfully fitted models.

  • df – pandas.DataFrame with samples to predict.

Returns:

pandas.DataFrame with predictions.

cva.DOE module

This module contains the design of experiment classes.

class cva.DOE.DesignOfExperiments

Bases: object

The design of experiments class contains all functions to create a design of experiments.

To define a design of experiments input variables must be set and the algorithm needs to be parameterized. Optionally, restrictions can be added.

add_restriction(name, cmp, crit)

Adds a restriction function to the design of experiments.

Parameters:
  • name – The name of the restriction. The name is also used as an identifier (column name) with evaluation function.

  • cmp – The comparator, one of: ‘<’, ‘<=’, ‘>’, ‘>=’

  • crit – Constant value for comparison with the return value of the function.

Raises:

CvaException – if the name is not unique or the comparator is unknown.

add_variable(name, lower_bound=0.0, upper_bound=0.0, vartype='real', class_names=[])

Adds a variable to the search space of this design of experiments.

Parameters:
  • name – The name of the variable.

  • lower_bound – The lower bound for a real valued variables.

  • upper_bound – The upper bound for a real valued variables.

  • vartype – The type of the variable, can be ‘real’ or ‘class’. ‘real’ needs bounds, ‘class’ needs a list of class names. class_names: The names of the classes used as values for this variable.

Raises:

CvaException – if name is not a unique identifier.

connect(manager=None)

Connect the design of experiments to an existing CVA manager.

Parameters:

manager – The CVA manager.

Raises:

CvaException – if the core operation did not succeed. The exceptions contains the reason.

create_design_of_experiments() DataFrame

Create the samples and return the design of experiments as a pandas.DataFrame.

Returns:

pandas.DataFrame containing the design of experiments.

Raises:

CvaException – if the core operation did not succeed. The exceptions contains the reason.

create_multiple_design_of_experiments(cnt)

Create the samples multiple times and return the designs of experiments as a concatenated pandas.DataFrame.

Parameters:

cnt – Numper of repetitions.

Returns:

pandas.DataFrame containing the design of experiments with an additional column with the iteration index.

Raises:

CvaException – if the core operation did not succeed. The exceptions contains the reason.

evaluate(input_df)

Evaluates all restrictions and return results in a single data frame.

Parameters:

input_df – pandas.DataFrame containing values for all input variables.

Returns:

pandas.DataFrame containing values for all restrictions.

get_doe() DataFrame

Returns the created design of experiments as a pandas.DataFrame.

Returns:

pandas.DataFrame containing the design of experiments.

Raises:

CvaException – if no design has been created yet.

get_model()

Return the model used for adaptive modeling design of experiments.

Returns:

A CVA model.

get_models()

Return the model list used for adaptive modeling design of experiments.

Returns:

The CVA model list.

get_parameters()

Returns all parameters of the design of experiments.

Returns:

Dictionary of parameters used by this design of experiments.

get_restriction_names()

Get the names of the restrictions defined for this design of experiments.

Returns:

The names of the restrictions as list of strings.

get_restrictions()

Returns all restrictions defined for this design of experiments.

Returns:

The list of restrictions.

get_variable_names()

Returns the names all search space variables.

Returns:

The names of variables as list of string.

get_variables()

Returns all variable objects.

Returns:

The list of variables used in this design of experiments.

remove_restriction(name)

Removes a restriction from this design of experiments.

Parameters:

name – Name of the restriction to remove.

remove_variable(name)

Removes a variable from the design of experiments.

Parameters:

name – Name of the variable to remove.

set_evaluation_function(evaluation_function)

The evaluation function must accept a pandas.DataFrame as input parameter and return another DateFrame. The returned pandas.DataFrame must contain all restrictions as columns and the same number of rows as the input pandas.DataFrame. 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).
Parameters:

evaluation_function – A function with pandas.DataFrame as input and output. (evaluation_function: pandas.DataFrame -> pandas.DataFrame)

set_existing_samples(df)

Set an initial sample. This is only useful for space-filling designs.

Parameters:

df – pandas.DataFrame containing samples.

set_model(model: Model)

Set a model for adaptive modeling design of experiments.

Parameters:

model – A CVA model.

set_models(models)

Set a list of models used for adaptive modeling design of experiments.

Parameters:

models – A CVA model list.

set_parameter(name, value)

Sets a design of experiments parameter. Parameter values will be stored and transferred to CVA as strings.

Parameters:
  • name – The name of the parameter.

  • value – The value of the parameter.

cva.Examples module

This module contains sample data sets for testing purposes.

cva.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).

cva.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 – 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).

cva.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 vector will not be a valid solution for the optimization.

Parameters:

vector – n-dimensional vector with n >= 2.

Returns:

Sum of first two entries.

cva.Examples.function_rosenbrock(vector)

Calculates the Rosenbrock function for an n-dimensional input vector.

Parameters:

vector – 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)\]

cva.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 – Vector of input values.

Returns:

Result of the n-dimensional sphere function (sum of squares).

cva.Examples.optimization_multi_objective_evaluation(dataFrame)

Applies the function function_sphere() and function_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    return dataFrame.apply([function_sphere, function_rosenbrock], axis=1)
Parameters:

dataFrame – pandas.DataFrame with input values.

Returns:

pandas.DataFrame containing inputs, function_sphere() and function_restriction() results in new columns.

cva.Examples.optimization_single_objective_evaluation(dataFrame)

Applies the function function_sphere() and function_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    return dataFrame.apply([function_sphere, function_restriction], axis=1)
Parameters:

dataFrame – pandas.DataFrame with input values.

Returns:

pandas.DataFrame containing inputs, function_sphere() and function_restriction() results in new columns.

cva.Models module

This module contains the model classes.

class cva.Models.EnsembleModel

Bases: object

Ensemble model class.

Hint

Model must be created using the function cva.Base.Manager.create_ensemble_model().

An ensemble model contains a list of pre-fitted models which are used to get better predictions. The models can be of different types or of the same type. There are currently four methods available to combine the predictions of the \(n\) models:

  • mean_predict (default): The mean of all predict values is calculated and returned.

\[y=\frac{\sum_{i=1}^{n} y_i}{n}\]
  • mean_weighted_predict: The predictions are weighted by their confidence and the mean weighted prediction is returned.

\[y=\frac{\sum_{i=1}^{n} y_i\cdot c_i}{\sum_{i=1}^{n} c_i}\]
  • mean_exp_weighted_predict: Before weighting the predictions, the predictions are sorted by the confidence and get a number by their position (first \(n\), second \(n-1\) … last \(1\)). The factors can be further altered by an exponential factor \(f\) (default: \(f=1\) see set_exp_weight_factor()).

\[y=\frac{\sum_{i=1}^{n} y_i\cdot c_i\cdot i^{f}}{\sum_{i=1}^{n} c_i} \text{ with } \forall c_i, c_j\in {c_1,...,c_n}:i<j\implies c_i<c_j\]
  • best_predict: Return the prediction with the highest confidence.

The predict mode can be set with set_predict_mode(). The ensemble model is a new model with all the dependent models integrated and thus the ensemble model can be saved and loaded independently.

connect(manager=None)

Connect the model to an existing CVA manager.

Parameters:

manager – The CVA manager.

Raises:

CvaException – if the core operation did not succeed. The exceptions contains the reason.

create_data_frame(rows=None)

Create a data frame matching the names of the inputs and the output.

Parameters:

rows – If rows is None an empty data frame is created. If rows is an integer, the data frame contains the corresponding number of rows pre-filled with NaNs.

Returns:

A data frame matching the model variables or None, if the model is not valid.

delete()

Remove model from C++ core to free memory. Python object becomes invalid.

Raises:

CvaException – if the core operation did not succeed. The exceptions contains the reason.

export(model_file_name)

Save model to disk. The model is saved as a xml files suited to be used with any CVA tool.

Parameters:

model_file_name – Name of the model file.

Raises:

CvaException – if the core operation did not succeed. The exceptions contains the reason.

fig_morris(df, figsize=(10, 10), markertextsize=10, titlesize=20, markersize=10, labelsize=15, ticksize=10, legendsize=10)

Create a standard deviation vs. mean scatter plot with colored areas for the results of Morris sensitivity analysis.

Hint

In order to create the plots, you need Matplotlib.

Parameters:
  • df – Data frame of self.sensitivity()

  • figsize – Same as figsize from matplotlib.subplots.

  • markertextsize – Integer for size of the markertext

  • titlesize – Integer for fontsize of the title

  • labelsize – Integer for fontsize of the x and y label

  • ticksize – Integer for size of the x and y ticks

  • legendsize – Integer for fontsize of text of the legend

  • markersize – Integer for size of the marker

Returns:

Handle to a matplotlib figure

Raises:

CvaException – if the Matplotlib package is not found.

fig_scatter(df, figsize=(10, 10), titlesize=20, labelsize=15, ticksize=15, legendsize=15, markersize=30)

Create a prediction vs. original values scatter plot for the final model and the cross-validation.

Hint

In order to create the plots, you need Matplotlib.

Parameters:
  • df – Data frame with a original_values and predicted_values data frame.

  • figsize – Same as figsize from matplotlib.subplots.

  • titlesize – Font size of the title.

  • labelsize – Font size of the x and y label.

  • ticksize – Size of the x and y ticks.

  • legendsize – Font size of text of the legend.

  • markersize – Ssize of the marker.

Returns:

Handle to a matplotlib figure

Raises:

CvaException – if the Matplotlib package is not found.

get_confusion_matrix(df=None)

Create a list of the confusion matrix of each model.

Parameters:
  • df – A data frame with a column “original_values” and a column “predicted_values”. If no data frame is given,

  • used. (the validation data frame is) –

Returns:

A list of data frames containing the confusion matrix of each model.

Raises:

CvaException – if the model is not a classifier or one of the needed columns is missing or if the model has not been fitted.

get_exp_weight_factor()

Get the factor for the exponential weighted predict mode of the ensemble model.

Returns:

The exponential weight factor.

Raises:

CvaException – if the core operation did not succeed. The exceptions contains the reason.

get_input_variable_class_names()

Get the names of the classes of the input variables.

Returns:

A dictionary with each class input variable name as key and a list of attached class names. None is returned, if the model has not been fitted.

get_input_variable_names()

Get the names of the input variables.

Returns:

The list of input variable names or None, if the model has not been fitted.

get_invalid_reason()

Get the reason for a failed fit.

Returns:

If the model is not valid return the reason or ‘’ if the model is valid.

get_model_type()

Get the model type.

Returns:

Always ‘ensemble_model’.

get_output_variable_class_names()

Get the names of the classes of the output variable.

Returns:

If the output is a class variable, a list of the class names is returned, else an empty list is returned. None is returned, if the model has not been fitted.

get_output_variable_name()

Get the name of the output variable.

Returns:

The name of the output variable or None, if the model has not been fitted.

get_predict_mode()

Get the predict mode of the ensemble model.

Returns:

The predict mode. One of ‘mean_predict’, ‘mean_weighted_predict’, ‘mean_exp_weighted_predict’, ‘best_predict’.

Raises:

CvaException – if the core operation did not succeed. The exceptions contains the reason.

get_qualities()

Get the quality data frame (see cva.Structures.CvaModelInfo).

Returns:

The quality data frame.

Raises:

CvaException – if the model has not been fitted.

get_validation_data_frame()

Get a list of data frames with comparison between original and predicted values for the internal validation for each model (see cva.Structures.CvaModelInfo).

Returns:

Data frames with the comparison.

Raises:

CvaException – if the model has not been fitted.

get_variable_importance()

Get the variable importance data frame list (see cva.Structures.CvaModelInfo).

Returns:

A list of data frames with the input variable importance for each model.

Raises:

CvaException – if the model has not been fitted.

get_variable_sensitivity()

Get the sensitivity in form of the Sobol indices for each model (see cva.Structures.CvaModelInfo).

Returns:

Data frames with the sensitivity for the input variables (Sobol index and total Sobol index) for each model.

Raises:

CvaException – if the model has not been fitted.

is_valid()

Check, if the model is valid.

Returns:

True, if all contained models are valid, otherwise False.

plot_morris(ax, df, markertextsize, titlesize, labelsize, ticksize, legendsize, markersize)

Create a standard deviation vs. mean scatter plot with colored areas for the results of Morris sensitivity analysis.

Hint

In order to create the plots, you need Matplotlib.

Parameters:
  • ax – Axis handle of a matplotlib figure.

  • df – Data frame with the sensitivity values either generated with cva.Model.get_sensitivity() or cva.Model.sensitivity()

  • markertextsize – Font size of the marker text.

  • titlesize – Font size of the title.

  • labelsize – Font size of the x and y label.

  • ticksize – Size of the x and y ticks.

  • legendsize – Font size of text of the legend.

  • markersize – Ssize of the marker.

Raises:

CvaException – if the Matplotlib package is not found.

plot_scatter(ax, df, titlesize, labelsize, ticksize, legendsize, markersize)

Create a prediction vs. original values scatter plot for the final model and the cross-validation.

Hint

In order to create the plots, you need Matplotlib.

Parameters:
  • ax – Axis handle of a matplotlib figure.

  • df – Data frame with a original_values and predicted_values data frame.

  • titlesize – Font size of the title.

  • labelsize – Font size of the x and y label.

  • ticksize – Size of the x and y ticks.

  • legendsize – Font size of text of the legend.

  • markersize – Ssize of the marker.

Raises:

CvaException – if the Matplotlib package is not found.

predict(df, confidence=True)

Predict values using new data.

The data frame needs to contain at least columns with names of the input variables.

Parameters:
  • df – Data frame to predict.

  • confidence – If true, calculate the confidence values, else return a list with NaNs for the confidence

Returns:

List with tuples of the predicted values and the confidence values or None, if the model is not valid. The confidence value is between one and zero, with one being the highest confidence.

sensitivity(box, sensitivity_types=['Sobol', 'Morris'])

Calculate variable sensitivity for a given sub-space.

Parameters:
  • box – A dictionary of the form variable -> [min, max] defining the box.

  • sensitivity_type – The methods to be applied.

Returns:

A pandas.DataFrame with a row for each input variable containing the selected sensitivity values.

set_exp_weight_factor(factor)

Set the factor for the exponential weighted predict mode of the ensemble model.

Parameters:

factor – The exponential weight factor.

Raises:

CvaException – if the core operation did not succeed. The exceptions contains the reason.

set_predict_mode(predict_mode)

Set the predict mode of the ensemble model.

Parameters:

predict_mode – The name of the predict mode. Possible values are mean_predict, mean_weighted_predict, mean_exp_weighted_predict, best_predict

Raises:

CvaException – if the predict mode is unknown.

class cva.Models.Model

Bases: object

Model class.

Hint

Model is created using the function cva.Base.Manager.create_model().

connect(manager=None)

Connect the model to an existing CVA manager.

Parameters:

manager – The CVA manager.

Raises:

CvaException – if the core operation did not succeed. The exceptions contains the reason.

create_data_frame(rows=None)

Create a data frame matching the names of the inputs and the output.

Parameters:

rows – If rows is None an empty data frame is created. If rows is an integer, the data frame contains the corresponding number of rows pre-filled with NaNs.

Returns:

A data frame matching the model variables or None, if the model is not valid.

delete()

Remove model from C++ core to free memory. Python object becomes invalid.

Raises:

CvaException – if the core operation did not succeed. The exceptions contains the reason.

export(model_file_name)

Save model to disk. The model is saved as a xml files suited to be used with any CVA tool.

Parameters:

model_file_name – Name of the model file.

Raises:

CvaException – if the core operation did not succeed. The exceptions contains the reason or if the model has not been fitted.

fig_morris(df, figsize=(10, 10), markertextsize=10, titlesize=20, markersize=10, labelsize=15, ticksize=10, legendsize=10)

Create a standard deviation vs. mean scatter plot with colored areas for the results of Morris sensitivity analysis.

Hint

In order to create the plots, you need Matplotlib.

Parameters:
  • df – Data frame of self.sensitivity()

  • figsize – Same as figsize from matplotlib.subplots.

  • markertextsize – Integer for size of the markertext

  • titlesize – Integer for fontsize of the title

  • labelsize – Integer for fontsize of the x and y label

  • ticksize – Integer for size of the x and y ticks

  • legendsize – Integer for fontsize of text of the legend

  • markersize – Integer for size of the marker

Returns:

Handle to a matplotlib figure

Raises:

CvaException – if the Matplotlib package is not found.

fig_scatter(df, figsize=(10, 10), titlesize=20, labelsize=15, ticksize=15, legendsize=15, markersize=30)

Create a prediction vs. original values scatter plot for the final model and the cross-validation.

Hint

In order to create the plots, you need Matplotlib.

Parameters:
  • df – Data frame with a original_values and predicted_values data frame.

  • figsize – Same as figsize from matplotlib.subplots.

  • titlesize – Font size of the title.

  • labelsize – Font size of the x and y label.

  • ticksize – Size of the x and y ticks.

  • legendsize – Font size of text of the legend.

  • markersize – Ssize of the marker.

Returns:

Handle to a matplotlib figure

Raises:

CvaException – if the Matplotlib package is not found.

fit(df, input_variable_names, output_variable_name)

Train the model using the model and task parameter set.

Parameters:
  • df – Learn data as data frame.

  • input_variable_names – List of input variable names.

  • output_variable_name – Name of the output variable.

Returns:

True, if the model fit has been successful, else False.

Raises:

CvaException – if the core operation did not succeed. The exceptions contains the reason.

get_confusion_matrix(df=None, class_names=None)

Get the confusion matrix for classification models.

Parameters:
  • df – 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.

  • class_names – The list of class names of the output variable. This list can be used to determine the order of the class names in the matrix. If not specified, the internal order is used.

Returns:

A data frame containing the confusion matrix.

Raises:

CvaException – if the model is not a classifier or one of the needed columns is missing or if the model has not been fitted.

get_fit_info()

Get the qualities and the parameters used to fit the model.

Returns:

A cva.Structures.CvaModelInfo structure with information on qualities, variable importance, variable sensitivity and more.

get_fit_task()

Get the task and model parameter for fitting.

Returns:

A cva.Structures.CvaFitTask structure with the parameters.

get_fit_task_model_parameter(name)

Get an initial model parameter for fitting by name.

Parameters:

name – The name of the model parameter.

Returns:

The model parameter object.

get_fit_task_model_parameters()

Get the initial model parameters for fitting.

Returns:

The model parameters.

get_fit_task_parameter(name)

Get a fit task parameter by name.

Parameters:

name – The name of the task parameter.

Returns:

The task parameter object.

get_fit_task_parameters()

Get the fit task parameters.

Returns:

The task parameters.

get_input_variable_class_names()

Get the names of the classes of the input variables.

Returns:

A dictionary with each class input variable name as key and a list of attached class names. None is returned, if the model has not been fitted.

get_input_variable_names()

Get the names of the input variables.

Returns:

The list of input variable names or None, if the model has not been fitted.

get_invalid_reason()

Get the reason for a failed fit.

Returns:

If the model is not valid return the reason or ‘’ if the model is valid.

get_model_parameter(name)

Get a model parameter used to fit the model by name.

Parameters:

name – The name of the model parameter.

Returns:

The model parameter object.

Raises:

CvaException – if the model has not been fitted.

get_model_parameters()

Get the model parameters used to fit the model.

Returns:

The model parameters.

Raises:

CvaException – if the model has not been fitted.

get_model_type()

Get the model type.

Returns:

The model type.

get_output_variable_class_names()

Get the names of the classes of the output variable.

Returns:

If the output is a class variable, a list of the class names is returned, else an empty list is returned. None is returned, if the model has not been fitted.

get_output_variable_name()

Get the name of the output variable.

Returns:

The name of the output variable or None, if the model has not been fitted.

get_qualities()

Get the quality data frame (see cva.Structures.CvaModelInfo).

Returns:

The quality data frame.

Raises:

CvaException – if the model has not been fitted.

get_task()

Get the task and model parameter used for fitting.

Returns:

A cva.Structures.CvaFitTask structure with the parameters used for fitting.

Raises:

CvaException – if the model has not been fitted.

get_task_parameter(name)

Get a fit task parameter used to fit the model by name.

Parameters:

name – The name of the task parameter.

Returns:

The task parameter object.

Raises:

CvaException – if the model has not been fitted.

get_task_parameters()

Get the fit task parameters used to fit the model.

Returns:

The task parameters.

Raises:

CvaException – if the model has not been fitted.

get_validation_data_frame()

Get the data frame with comparison between original and predicted values for the internal validation (see cva.Structures.CvaModelInfo).

Returns:

Data frame with the comparison.

Raises:

CvaException – if the model has not been fitted.

get_variable_importance()

Get the variable importance data frame (see cva.Base.Structure.CvaModelInfo).

Returns:

A data frame with the input variable importance.

Raises:

CvaException – if the model has not been fitted.

get_variable_sensitivity(sensitivity_types=['Sobol', 'Morris'])

Get the train sensitivity using Sobol and/or Morris method (see cva.Structures.CvaModelInfo).

Returns:

A data frame with the sensitivity for the input variables (Sobol index and total Sobol index, Morris mean, Morris sntadard deviation).

Raises:

CvaException – if the model has not been fitted or no sensitivity type is valid.

is_valid()

Check, if the model is valid.

Returns:

True, if models has been fitted and is valid, otherwise False.

plot_morris(ax, df, markertextsize, titlesize, labelsize, ticksize, legendsize, markersize)

Create a standard deviation vs. mean scatter plot with colored areas for the results of Morris sensitivity analysis.

Hint

In order to create the plots, you need Matplotlib.

Parameters:
  • ax – Axis handle of a matplotlib figure.

  • df – Data frame with the sensitivity values either generated with cva.Model.get_sensitivity() or cva.Model.sensitivity()

  • markertextsize – Font size of the marker text.

  • titlesize – Font size of the title.

  • labelsize – Font size of the x and y label.

  • ticksize – Size of the x and y ticks.

  • legendsize – Font size of text of the legend.

  • markersize – Ssize of the marker.

Raises:

CvaException – if the Matplotlib package is not found.

plot_scatter(ax, df, titlesize, labelsize, ticksize, legendsize, markersize)

Create a prediction vs. original values scatter plot for the final model and the cross-validation.

Hint

In order to create the plots, you need Matplotlib.

Parameters:
  • ax – Axis handle of a matplotlib figure.

  • df – Data frame with a original_values and predicted_values data frame.

  • titlesize – Font size of the title.

  • labelsize – Font size of the x and y label.

  • ticksize – Size of the x and y ticks.

  • legendsize – Font size of text of the legend.

  • markersize – Ssize of the marker.

Raises:

CvaException – if the Matplotlib package is not found.

predict(df, confidence=True)

Predict values using new data.

The data frame needs to contain at least columns with names of the input variables. For more information on confidence see using models.

Parameters:
  • df – Data frame to predict.

  • confidence – If true, calculate the confidence values, else return a list with NaNs for the confidence

Returns:

List with tuples of the predicted values and the confidence values or None, if the model is not valid. The confidence value is between one and zero, with one being the highest confidence.

sensitivity(box, sensitivity_types=['Sobol', 'Morris'])

Calculate variable sensitivity for a given sub-space.

Parameters:
  • box – A dictionary of the form variable -> [min, max] / variable -> labels defining the box.

  • sensitivity_type – The methods to be applied.

Returns:

A pandas.DataFrame with a row for each input variable containing the selected sensitivity values.

set_fit_task_model_parameter(name, value)

Set an initial model parameter for fitting by name.

Parameters:
  • name – The name of the model parameter.

  • value – The new value for the parameter.

set_fit_task_model_parameters(parameters)

Set the initial model parameters for fitting.

Parameters:

parameters – The new parameters.

set_fit_task_parameter(name, value)

Set the value of a fit task parameter by the name.

Parameters:
  • name – The name of the task parameter.

  • value – The new value for the parameter.

set_fit_task_parameters(parameters)

Set the fit task parameters.

Parameters:

parameters – The new parameters.

show_fit_info()

Print the qualities of the model

show_fit_task()

Print the task and model parameters for fitting.

class cva.Models.UserModelInterface(model)

Bases: object

Template class for building a user model. The user model class can be derived from this class. The actual implementation of the user algorithm must be given as a reference to the constructor and must work with pickle for storing/loading.

Hint

A user model is created using the function cva.Base.Manager.create_user_model() with an object implementing the function of this interface.

 1class UserModelInterface:
 2    '''
 3    Template class for building a user model. The user model class can be derived from this class. The actual implementation
 4    of the user algorithm must be given as a reference to the constructor and must work with pickle for storing/loading.
 5
 6    .. hint:: A user model is created using the function :py:meth:`cva.Base.Manager.create_user_model` with an object implementing the function of this interface.
 7
 8    .. code-block:: python
 9        :linenos:
10
11        y, c = model.predict(df, confidence = False)
12    '''
13
14    def __init__(self, model) -> None:
15        self.model = model
16
17    def get_parameter_list(self, input_cnt) -> list:
18        ''' This function should return the list of parameters / hyper-parameters which can be configured or optimized.
19
20        Args:
21            input_cnt: In order to properly initialize the parameters, the number of input variables is provided.
22
23        Returns:
24            A list of parameters of type :py:class:`cva.Base.Structures.CvaModelParameter`.
25        '''
26        return []
27
28    def set_parameter_values(self, parameter_values) -> None:
29        ''' This function changes the current parameter values.
30
31        Args:
32            parameter_values: A dictionary of name value pairs for the parameters to be changed.
33        '''
34        pass
35
36    def fit(self, df, input_variable_names, output_variable_name) -> None:
37        ''' The fit function should provide the actual training algorithm for the user model. The resulting model should be stored in self.model.
38
39        Args:
40            df: Learn data as data frame.
41            input_variable_names: List of input variable names.
42            output_variable_name: Name of the output variable.
43        '''
44        pass
45
46    def predict(self, df, input_variable_names, output_variable_name):
47        ''' Predict values using new data.
48
49        Args:
50            df: Data frame to predict.
51
52        Returns:
53            A pandas.DataFrame containing one column "output_variable_name" with predictions.
54        '''
55        pass
fit(df, input_variable_names, output_variable_name) None

The fit function should provide the actual training algorithm for the user model. The resulting model should be stored in self.model.

Parameters:
  • df – Learn data as data frame.

  • input_variable_names – List of input variable names.

  • output_variable_name – Name of the output variable.

get_parameter_list(input_cnt) list

This function should return the list of parameters / hyper-parameters which can be configured or optimized.

Parameters:

input_cnt – In order to properly initialize the parameters, the number of input variables is provided.

Returns:

A list of parameters of type cva.Base.Structures.CvaModelParameter.

predict(df, input_variable_names, output_variable_name)

Predict values using new data.

Parameters:

df – Data frame to predict.

Returns:

A pandas.DataFrame containing one column “output_variable_name” with predictions.

set_parameter_values(parameter_values) None

This function changes the current parameter values.

Parameters:

parameter_values – A dictionary of name value pairs for the parameters to be changed.

cva.Optimizations module

This module contains the optimization classes.

class cva.Optimizations.Optimization

Bases: object

The Optimization class contains all necessary methods to setup and start an optimization run.

Input variables, objective functions, and restriction functions can be added. Optimization parameters can be set, ‘start’ and ‘continue_run’ can be used to control to perform a single, or an extended optimization. get_results() returns the best solutions found. get_history() returns all created candidate solutions, including objective and restriction values and generation.

add_objective(name, obj_type='Minimize', obj_value=0.0)

Adds an objective to the optimization.

Parameters:
  • name – The name of the objective, also the name for the data column.

  • obj_type – The type of the objective, may be ‘Minimize’, ‘Maximize’, or ‘Value.

  • obj_value – The target value to use, when obj_type is set to ‘Value’.

add_restriction(name, cmp, crit)

Add a restriction function to the optimization.

Parameters:
  • name – The (column) name.

  • cmp – The comparator, one of: ‘<’, ‘<=’, ‘>’, ‘>=’

  • crit – Constant value for comparison with the return value of the function.

Raises:

CvaException – if the name is not unique or the comparator is unknown.

add_variable(name, lower_bound=0.0, upper_bound=1.0, vartype='real', class_names=[])

Add a design space variable.

Parameters:
  • name – The name of the variable.

  • lower_bound – The lower bound for a real valued variables.

  • upper_bound – The upper bound for a real valued variables.

  • vartype – The type of the variable, can be ‘real’ or ‘class’. ‘real’ needs bounds, ‘class’ needs a list of class names.

  • class_names – The names of the classes if vartype is ‘class’.

connect(manager=None)

Connect the optimization to an existing CVA manager.

Parameters:

manager – The CVA manager.

Raises:

CvaException – if the core operation did not succeed. The exceptions contains the reason.

continue_run(generations)

Continue the optimization process for the given number of generations.

Parameters:

generations – number of generations to continue.

Returns:

pandas.DataFrame containing the optimization results.

delete()

Clear the used memory and delete the results of the optimization.

evaluate(input_df)

Evaluates all fitness and restriction functions and return results in a single data frame.

Parameters:

input_df – pandas.DataFrame containing values for all input variables.

Returns:

pandas.DataFrame containing values for all objectives and restrictions.

get_history()

Returns the complete optimization history which contains all individuals that have been created in the process.

Returns:

Complete optimization history.

get_initial_parents()

Get the data frame with initial parents.

Returns:

pandas.DataFrame with the initial parents if set, else None

get_objective_names()

Get the names of the objectives of the optimization.

The names of the optimizations have to match the names of the columns in the data frame returned by evaluation function.

Returns:

The names of all objectives as list of strings.

get_objectives()

Get the objective of the optimization.

The names of the optimizations have to match the names of the columns in the data frame returned by evaluation function.

Returns:

The list of objectives.

get_parameters()

Get the optimization parameters.

Returns:

Dictionary of parameters used by this optimization.

get_restriction_names()

Get the names of the restrictions of the optimization.

The names of the restrictions have to match the names of the columns in the data frame returned by evaluation function.

Returns:

The names of the restrictions as list of strings.

get_restrictions()

Get the restrictions of the optimization.

The names of the restrictions have to match the names of the columns in the data frame returned by evaluation function.

Returns:

The list of restrictions.

get_result()

Returns the best individuals found in this optimization run.

This is the same result which is returned by the start method. Use get_result when you want to get the results of an optimization object that has finished. E.g. optimizations passed to other functions, loaded from hard disk, …

Returns:

The best solutions found by this optimization.

get_status()

Get the status of the optimization.

get_variable_names()

Get the design variable names.

Returns:

The names of the design variables as list of strings.

get_variables()

Get the design variables.

Returns:

The list of design variables used in this optimization.

remove_initial_parents()

Remove the initial parents and uses random initial parents instead.

remove_objective(name)

Removes an objective from the optimization.

Parameters:

name – Name of the objective to remove.

remove_restriction(name)

Removes a restriction from the optimization.

Parameters:

name – Name of the restriction to remove.

remove_variable(name)

Removes a variable from the optimization.

Parameters:

name – Name of the variable to remove.

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 restrictions and objectives 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 objective or restriction in this optimization object, the returned data frame has to contain a column with the name of that objective or restriction.

Parameters:

evaluation_function – A function with pandas.DataFrame as input and output. (evaluation_function: pandas.DataFrame -> pandas.DataFrame)

set_initial_parents(df_parents)

Set initial parents in form of a data frame.

Parameters:

df_parents – A pandas.DataFrame containing the initial parents. The data frame must contain columns named as the input variables. IF the objective / restrictions values are also known, they can also be added. This prevents unnecessary evaluations.

set_parameter(name, value)

Sets an optimization parameter. Parameter values will be stored and transferred to CVA as strings.

Parameters:
  • name – The name of the parameter.

  • value – The value of the parameter.

start()

Runs the optimization loop. The evaluation stops aft MaxGeneration.

Returns:

Optimization result (Pareto front) after MaxGeneration iterations.

Raises:

CvaException – if the core operation did not succeed. The exceptions contains the reason.

class cva.Optimizations.SolutionSpaceOptimization

Bases: object

Class 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 – The name of the input variable.

  • lower_bound – The lower bound for a real valued variables.

  • upper_bound – The upper bound for a real valued variables.

  • value – The value. Only used if the variable is not an interval.

  • labels – 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 – The name of the input variable.

  • lower_crit – The lower critical value for a real valued variables.

  • upper_crit – The upper critical value for a real valued variables.

  • bad_labels – 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 – A box in the form of a dictionary. Each item consists of the variable name and an interval.

Returns:

The normalized length of the diagonal.

box_norm_edge_sum(box)

A possible quality evaluation function for boxes.

Here, the sum of all normalized edges is calculated.

Parameters:

box – A box in the form of a dictionary. Each item consists of the variable name and an interval.

Returns:

The sum of normalized edges.

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 – A box in the form of a dictionary. Each item consists of the variable name and an interval.

Returns:

The normalized volume of the box.

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 – A box in the form of a dictionary. Each item consists of the variable name and an interval.

Returns:

The weighted sum of normalized edges.

check()

Check, if the values set are valid.

Returns:

List of tuple of (True, if everything is okay, else False / Fail message)

check_input(name)

Check, if the values of the input variable are valid.

Parameters:

name – Name of the variable.

Returns:

Tuple of (True, if everything is okay, else False / Fail message)

Raises:

CvaException – if no variable is found.

check_output(name)

Check, if the values of a output variable are valid.

Parameters:

name – Name of the variable.

Returns:

Tuple of (True, if everything is okay, else False / Fail message)

Raises:

CvaException – if no variable is found.

connect(manager=None)

Connect the model to an existing CVA manager.

Parameters:

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 output ranges with a design of experiment.

Parameters:
  • num_samples – Number of samples for the estimation.

  • apply – If set to True, the ranges are used to set the norm values of the outputs.

Returns:

dictionary with the ranges for each output.

evaluate_sample(input_data)

Takes an existing sample, evaluates all outputs and checks the critical values.

Parameters:

input_data – 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()).

get_history()

Get the optimization history.

Parameters:

name – Name of the variable.

Returns:

A dictionary of the boxes that are calculated by the optimization. The keys are the generations. Each generation contains a dictionary with the type, parent or offspring, as key and the calculated box and its quality in a list as values.

Raises:

CvaException – if no history is found.

get_initial_boxes()

Get initial boxes.

Returns:

List of boxes.

get_initial_qualities()

Get the qualities of pre-defined initial boxes.

Returns:

List of quality values.

get_input(name)

Get input variable by name.

Parameters:

name – Name of the variable.

Returns:

Input variable (cva.Structures.CvssInputVariable).

Raises:

CvaException – if no variable is found.

get_input_class_names(name)

Get the attribute names of a class input variable.

Parameters:

name – 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.

get_input_is_class_names_fixed(name)

Get if the class names of a class input variable are fixed.

Parameters:

name – Name of the variable.

Returns:

True if the class names are fixed.

Raises:

CvaException – if no variable is found.

get_input_is_interval(name)

Get if the result should be an interval/subset or a single value/class.

Parameters:

name – 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.

get_input_is_lower_fixed(name)

Get if the lower bound is fixed.

Parameters:

name – Name of the variable.

Returns:

True, if the bound is fixed, else False.

Raises:

CvaException – if no variable is found.

get_input_is_upper_fixed(name)

Get if the upper bound is fixed.

Parameters:

name – Name of the variable.

Returns:

True, if the bound is fixed, else False.

Raises:

CvaException – if no variable is found.

get_input_is_value_fixed(name)

Get if the single value is fixed (Only used if is_interval = False).

Parameters:

name – Name of the variable.

Returns:

True, if the value is fixed, else False.

Raises:

CvaException – if no variable is found.

get_input_is_width_fixed(name)

Get if the width is fixed (Only used if is_interval = True).

Parameters:

name – Name of the variable.

Returns:

True, if the width is fixed, else False.

Raises:

CvaException – if no variable is found.

get_input_lower_bound(name)

Get the lower bound of a real-valued input variable.

Parameters:

name – Name of the variable.

Returns:

lower bound of the input variable

Raises:

CvaException – if no variable is found.

get_input_upper_bound(name)

Get the upper bound of a real-valued input variable.

Parameters:

name – Name of the variable.

Returns:

Upper bound of the input variable

Raises:

CvaException – if no variable is found.

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 – Name of the variable.

Returns:

The lower bound of the upper bound of the edge or None if not used.

get_input_value(name)

Get the fixed value (Only used if is_interval = False and is_fixed = True).

Parameters:

name – 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.

get_input_width(name)

Gets a fixed width of a real-valued input (only used if is_width = True).

Parameters:

name – Name of the variable.

Returns:

The fixed width of the interval.

Raises:

CvaException – if no variable is found.

get_inputs()

Get input variables.

Returns:

List of input variables (cva.Structures.CvssInputVariable).

get_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 – Name of the variable.

Returns:

The upper bound of the lower bound of the edge or None if not used.

get_output(name)

Get output variable by name.

Parameters:

name – Name of the variable.

Returns:

Output variable (cva.Structures.CvssOutputVariable).

Raises:

CvaException – if no variable is found.

get_output_bad_labels(name)

Get the bad labels of a class output variable.

Parameters:

name – 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.

get_output_crit_low(name)

Get the critical lower bound of an output variable.

Parameters:

name – Name of the variable.

Returns:

Critical minimum value as double. Can be NaN.

Raises:

CvaException – if no variable is found.

get_output_crit_up(name)

Get the critical upper bound of an output variable.

Parameters:

name – Name of the variable.

Returns:

Critical maximal value as double. Can be NaN.

Raises:

CvaException – if no variable is found.

get_output_low_crit_norm(name)

Get the critical lower norm value of an output variable.

Parameters:

name – 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 – 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 (cva.Structures.CvssOutputVariable).

get_parameter(name)

Get an optimization parameter.

Parameters:

name – The name of the parameter.

Returns:

The parameter with the given name.

get_parameters()

Get optimization parameters.

Returns:

Dictionary of parameters used by this optimization.

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.

optimize(estimate_output_ranges=False, return_crit_changes=False)

Start the optimization.

Parameters:
  • estimate_output_ranges – If set to True, an initial design of experiment is done and the ranges of each output are estimated. The results are used to adjust the norm values of the outputs to make them comparable.

  • return_crit_changes – If set to True, a design of experiment is done after the optimization and the a dictionary with the new critical values is returned in addition to the optimization results.

Returns:

Tuple of (list of boxes / List of qualities of the boxes), if return_crit_changes is False, else a Triple of (list of boxes / List of qualities of the boxes / dictionary of changes to critical values).

Raises:

CvaException – if settings are invalid.

position(box)

Position a box in the design space so that a minimal adaptation of the critical values is necessary. The width of the edges are internally fixed.

Parameters:

box – A dictionary with an interval/label set for each input variable.

remove_input(name)

Remove input variable by name.

Parameters:

name – 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 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 – A dictionary representing a box as returned by optimize().

  • sample_size – The number of samples created. Standard is 100.

  • algorithm – Can be ‘LHS’, ‘monte-carlo’, ‘space-filling’, ‘FullFactorial’, ‘FractionalFactorial’, ‘FractionalFactorialL3’, ‘DOptimal’, ‘BoxBehnken’ or ‘Sobol’

Returns:

Tuple of (the generated input data in the form of a pandas.DataFrame, the result of calling evaluate_sample()).

set_box_evaluation_function(box_evaluation_function)

Set the box evaluation function.

If all samples are good in a box, you 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 – 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 – A function with pandas.DataFrame as input and output. (evaluation_function: pandas.DataFrame -> pandas.DataFrame)

set_initial_boxes(initial_boxes, qualities=[])

Get initial qualities of pre-defined initial boxes.

Returns:

List of quality values.

set_input_class_names(name, class_names)

Set the attribute names of a class input variable.

Parameters:
  • name – Name of the variable.

  • class_names – 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 – Name of the variable.

  • value – 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 – Name of the variable.

  • is_interval – 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 – Name of the variable.

  • is_fixed – 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 – Name of the variable.

  • is_fixed – 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 – Name of the variable.

  • is_fixed – 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 – Name of the variable.

  • is_fixed – 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 – Name of the variable.

  • lower_bound – 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 – Name of the variable.

  • value – 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 – Name of the variable.

  • upper_bound – Upper 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 – Name of the variable.

  • value – 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 – Name of the variable.

  • value – 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 – 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 – Name of the variable.

  • bad_labels – 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 – Name of the variable.

  • crit_low – 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 – Name of the variable.

  • crit_up – 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 – Name of the variable.

  • crit_norm – 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)

Helper function to directly set the norm values for the outputs. Class outputs ignore the range.

Parameters:

norm_dict – A dictionary with ranges for each output as returned from estimate_output_ranges().

set_output_up_crit_norm(name, crit_norm)

Set the critical upper norm value of an output variable.

Parameters:
  • name – Name of the variable.

  • crit_norm – 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. Parameter values will be stored and transferred to CVA as strings.

Parameters:
  • name – The name of the parameter.

  • value – The value of the parameter.

test_sample(evaluated_data)

Checks, if samples are good or bad.

Parameters:

evaluated_data – 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’.

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 – Name of the input variable.

  • interval – the interval in the form of [lower, upper].

Returns:

The relative width.

cva.Structures module

This module contains wrapper for variables, parameters and results.

class cva.Structures.CvaDesignOfExperimentsInfo

Bases: object

Objects 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() DataFrame

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.

get_model()

Get the model to be used with an adaptive modeling design.

Returns:

The CVA model.

get_models()

Get the models to be used with an adaptive modeling design.

Returns:

The CVA model.

get_parameters()

The list of CvaParameter objects.

Returns:

List of CvaParameter.

get_restrictions()

The list of restriction function objects.

Returns:

List of CvaRestriction.

get_variables()

The list of input variable objects.

Returns:

List of CvaVariable objects.

set_doe(doe)

Set the created design of experiments.

Parameters:

doe – 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 – A pandas.DataFrame containing the existing samples.

set_model(model)

Set a model used for an adaptive modeling design.

Parameters:

model – A CVA model.

set_models(models)

Set models to used for an adaptive modeling design.

Parameters:

model – A CVA model.

class cva.Structures.CvaFitTask(c_model_template_paramer=None)

Bases: object

Container 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_parameters()

Get model parameter.

Returns:

Dictionary of model parameters (cva.Structures.CvaModelParameter).

get_model_type()

Get the model type.

Returns:

The model type.

get_task_parameters()

Get task parameters.

Returns:

Dictionary of task parameters (cva.Structures.CvaTaskParameter).

set_model_parameters(model_parameters)

Set model parameter.

Parameters:

model_parameters – Dictionary of model parameters (cva.Structures.CvaModelParameter).

class cva.Structures.CvaFunction(name)

Bases: object

Base class for objective and restriction functions.

get_name()

Names of functions, restrictions, and variables have to be unique identifiers.

Returns:

The name of the function object.

class cva.Structures.CvaModelCompare(c_model_compare, models)

Bases: object

CVA model compare information containing which models are best and comparison matrices.

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.

get_winner()

Get the winner model.

Returns:

The best model of the comparison.

get_wins()

Get how many times a model won against other models.

Returns:

A list of how many times a model won against another.

class cva.Structures.CvaModelInfo(c_model_info, fit_task, input_names, output_name, output_class_names, original_output_values)

Bases: object

CVA 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 – 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.

Returns:

A data frame containing the confusion matrix.

Raises:

CvaException – if the model is not a classifier or one of the needed columns is missing.

get_fit_task()

Get fit task.

Returns:

A CvaFitTask object containing the parameters used to fit the model.

get_invalid_reason()

If the model is not valid, get the reason or ‘’ if the model is valid.

Returns:

The reason for failure.

get_is_valid()

Check, if the model is valid.

Returns:

True, if the model has been successfully fitted, else False.

get_model_type()

Get the model type.

Returns:

The model type.

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.

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.

get_variable_importance()

Get the variable importance data frame (see CvaModelInfo).

Returns:

A pandas.DataFrame with the input variable importance.

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).

class cva.Structures.CvaModelParameter(name, value, value_type, enums=[], description='', is_optimizable=False, opt_min=nan, opt_max=nan)

Bases: CvaParameter

CVA modeling parameter extending the normal parameters by is optimizable and optimization limits. The arguments for the constructor are:

  • name: Name of the parameter.

  • value: Default value of the parameter.

  • value_type: Value type of the parameter (“integer”, “float”, “boolean”, “enum”, “string”).

  • enums: List of names, if the value type is “enum”.

  • description: Short description of the parameter.

  • is_optimizable: If true, this is a hyperparameter which is optimized, else it is a configurable parameter.

  • opt_min: If this is a hyperparameter, this is the lower limit (only needed for value_type float and integer).

  • opt_max: 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.

get_opt_max()

Get the upper bound of the optimization range.

Returns:

The upper bound.

Raises:

CvaException – if the parameter is not optimizable.

get_opt_min()

Get the lower bound of the optimization range.

Returns:

The lower bound.

Raises:

CvaException – if the parameter is not optimizable.

to_dict()
class cva.Structures.CvaObjective(name, obj_type='Minimize', obj_value=0.0)

Bases: CvaFunction

Wrapper class for objective functions.

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.

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.

class cva.Structures.CvaOptimizationInfo

Bases: object

Objects 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.

get_objectives()

The list of objective function objects.

Returns:

List of CvaObjective.

get_parameters()

Get the parameters.

Returns:

Dictionary of CvaParameter.

get_restrictions()

The list of restriction function objects.

Returns:

List of CvaRestriction.

get_variables()

The list of input variable objects.

Returns:

List of CvaVariable.

set_generations(generations)

Sets the maximum number of generations to be performed by an optimization task.

Parameters:

generations – Maximum number of optimization loop iterations.

set_parameters(parameters)

Set the optimization parameters.

Parameters:

parameters – Dictionary of CvaParameter.

class cva.Structures.CvaParallelTask(model, input_variable_names, output_variable_name, df, check_path, check_type, with_flask, flask_port=None)

Bases: object

Structure containing information for a modeling task. This structure is intended to be used with the parallel interface.

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.

flask_port

If user models are used, flask is needed

input_variable_names

The input variable names.

model

The model (cva.Models.Model) created by the manager.

output_variable_name

The output variable name.

with_flask

If user models are used, flask is needed

class cva.Structures.CvaParameter(name, value, value_type, enums=[], description='')

Bases: object

CVA parameter including name, description, value and value type. The arguments for the constructor are:

  • name: Name of the parameter.

  • value: Default value of the parameter.

  • value_type: Value type of the parameter (“integer”, “float”, “boolean”, “enum”, “string”).

  • enums: List of names, if the value type is “enum”.

  • description: Short description of the parameter.

get_description()

Get additional description on the parameter.

Returns:

Additional description, if available.

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.

get_name()

Get the name of the parameter.

Returns:

The name of the parameter.

get_value()

Get the current value of the parameter.

Returns:

The value.

get_value_type()

Get the value type.

Returns:

The value type.

init_from(parameter)
set_value(value)

Set a new value for the parameter.

Parameters:

value – 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.

class cva.Structures.CvaRestriction(name, cmp, crit)

Bases: CvaFunction

Wrapper 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.

check(values)

Check values if they fulfill the restriction.

Parameters:

values – Values to be checked.

Returns:

A list of booleans. True if the check is passed else False.

distance(values)

Calculate the distances to the critical value.

Parameters:

values – Values to be checked.

Returns:

A list of booleans. True if the check is passed else False.

get_comparator()

Get the comparator.

Returns:

The comparator as string.

get_value()

Get the critical value.

Returns:

The critical value (bound).

class cva.Structures.CvaSolutionSpaceOptimizationInfo

Bases: object

Objects 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()

A dictionary of CvaParameter objects.

Returns:

Dictionary of CvaParameter

init_from(info)
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 cva.Structures.CvaTaskParameter(name, value, value_type, enums=[], description='')

Bases: CvaParameter

CVA task parameter extending normal parameters.

Hint

Objects are provided from internal classes and should not be created by the user.

class cva.Structures.CvaVariable(c_variable)

Bases: object

Wrapper for variables.

Hint

Objects are provided from internal classes and should not be created by the user.

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.

get_id()

Get the core id (internal use only).

Returns:

The core id.

get_lower_bound()

Get the valid minimum value of a variable.

Returns: Minimum value.

get_name()

Get the name of the variable.

Returns:

Name of the variable.

get_type()

Get the type of a variable (class or real).

Returns: The type of the variable.

get_upper_bound()

Get the valid maximum value of a variable.

Returns: Maximum value.

set_properties(name, lower_bound=0.0, upper_bound=0.0, vartype='real', class_names=[])

Set the properties of a variable.

Parameters:
  • name – Name of the variable.

  • minimum – Minimum value

  • maximum – Maximum value

  • vartype – Type can be real, metric (same as real), or class

  • class_names – List of names (set of valid values) for a nominal variable.

class cva.Structures.CvssInputVariable

Bases: object

Wrapper 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).

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.

get_is_class_names_fixed()

Get if the class labels are fixed.

Returns:

True, if the class labels are fixed, else False.

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.

get_is_lower_fixed()

Get if the lower bound is fixed.

Returns:

True, if the bound is fixed, else False.

get_is_upper_fixed()

Get if the upper bound is fixed.

Returns:

True, if the bound is fixed, else False.

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.

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.

get_lower_bound()

Get the lower bound of a real-valued variable.

Returns:

lower bound of the variable.

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.

get_name()

Get the name of the variable.

Returns:

Name of the variable.

get_type()

Get the type of a variable (class or real).

Returns:

Variable type as string

get_upper_bound()

Get the upper bound of a real-valued variable.

Returns:

Upper bound of the variable.

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.

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..

get_width()

Gets a fixed width of a real-valued input (only used if is_width = True).

Returns:

The fixed width of the interval.

init_from(variable)
set_class_names(class_names)

Set the attribute names of a class variable.

Parameters:

class_names – 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 – 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 – 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 – True, if the bound is fixed, else False.

set_is_upper_fixed(is_fixed)

Set if the upper bound is fixed.

Parameters:

is_fixed – 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 – 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 – 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 – 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 – 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 – Name of the variable.

  • lower_bound – Lower design space bound.

  • upper_bound – Upper design space bound.

  • value – The value is needed if the input variable should be fixed at a certain value or class name.

  • vartype – Type can be real, metric (same as real), or class

  • class_names – 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 – 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 – 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 – 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 – The fixed width of the interval.

class cva.Structures.CvssOutputVariable

Bases: object

Wrapper 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).

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.

get_crit_low()

Get the critical lower bound of an output variable.

Returns:

Critical minimum value as double. Can be NaN.

get_crit_up()

Get the critical upper bound of an output variable.

Returns:

Critical maximal value as double. Can be NaN.

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.

get_type()

Get the type of a variable (class or real).

Returns:

Variable type as string.

get_up_crit_norm()

Get the critical upper norm value of an output variable.

Returns:

Norm value.

Return type:

crit_norm

init_from(variable)
set_bad_labels(bad_labels)

Set the bad labels of a class output variable.

Parameters:

bad_labels – 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 – 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 – 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 – 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 – Name of the variable.

  • crit_low – Minimum value

  • crit_up – Maximum value

  • vartype – Type can be real, metric (same as real), or class

  • bad_labels – 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 – Norm value. Must be set and not 0. if crit_up is not NaN.

cva.Structures.create_default_doe_parameter()

Create common design of experiments parameter with default values.

Returns:

Dictionary of default parameter.

cva.Structures.create_default_optimization_parameter()

Create common optimization parameter with default values.

Returns:

Dictionary of default parameter.

cva.Structures.create_default_solution_space_optimization_parameter()

Create common optimization parameter with default values.

Returns:

Dictionary of default parameter.

cva.Structures.create_default_task_parameters()

Create common task parameters with default values.

Returns:

Dictionary of default parameter.

cva.Structures.create_task(manager, model_type)

Create task and model parameters with default values for a specific model type.

Parameters: