profit.sur

Subpackages

Submodules

Package Contents

Classes

Surrogate

Base class for all surrogate models.

class profit.sur.Surrogate[source]

Bases: profit.util.base_class.CustomABC

Base class for all surrogate models.

trained

Flag that indicates if the model is already trained and ready to make predictions.

Type:

bool

fixed_sigma_n

Indicates if the data noise should be optimized or not.

Type:

bool

Xtrain

Input training points.

Type:

ndarray

ytrain

Observed output data. Vector output is supported for independent variables only.

Type:

ndarray

ndim

Dimension of input data.

Type:

int

output_ndim

Dimension of output data.

Type:

int

input_encoders

Encoding used on input data.

Type:

list of profit.sur.encoders.Encoder

output_encoders

Encoding used on output data.

Type:

list of profit.sur.encoders.Encoder

Default parameters:

surrogate: GPy save: ./model_{surrogate label}.hdf5 load: False fixed_sigma_n: False input_encoders: [{‘class’: ‘exclude’, ‘columns’: {constant columns}

{‘class’: ‘log10’, ‘columns’: {log input columns}, ‘parameters’: {}}, {‘class’: ‘normalization’, ‘columns’: {input columns}, ‘parameters’: {}}]

output_encoders: [{‘class’: ‘normalization’, ‘columns’: {output columns}, ‘parameters’: {}}]

labels
encode_training_data()[source]

Encodes the input and output training data.

decode_training_data()[source]

Applies the decoding function of the encoder in reverse order on the input and output training data.

encode_predict_data(x)[source]

Transforms the input prediction points according to the encoder used for training.

Parameters:

x (ndarray) – Prediction input points.

Returns:

Encoded and normalized prediction points.

Return type:

ndarray

decode_predict_data(ym, yv)[source]

Rescales and then back-transforms the predicted output.

Parameters:
  • ym (ndarray) – Predictive output.

  • yv (ndarray) – Variance of predicted output.

Returns:

a tuple containing:
  • ym (ndarray) Rescaled and decoded output values at the test input points.

  • yv (ndarray): Rescaled predictive variance.

Return type:

tuple

add_input_encoder(encoder)[source]

Add encoder on input data.

Parameters:

encoder (profit.sur.encoder.Encoder) –

add_output_encoder(encoder)[source]

Add encoder on output data.

Parameters:

encoder (profit.sur.encoder.Encoder) –

abstract train(X, y, fixed_sigma_n=defaults['fixed_sigma_n'])[source]

Trains the surrogate on input points X and model outputs y.

Depending on the surrogate, the signature can vary.

Parameters:
  • X (ndarray) – Input training points.

  • y (ndarray) – Observed output data.

  • fixed_sigma_n (bool) – Whether the noise \(\sigma_n\) is fixed during optimization.

pre_train(X, y)[source]

Check the training data

Parameters:
  • X – (n, d) or (n,) array of input training data.

  • y – (n, D) or (n,) array of training output.

post_train()[source]
abstract predict(Xpred, add_data_variance=True)[source]

Predicts model output y for input Xpred based on surrogate.

Parameters:
  • Xpred (ndarray/list) – Input points for prediction.

  • add_data_variance (bool) – Adds the data noise \(\sigma_n^2\) to the prediction variance. This is especially useful for plotting.

Returns:

a tuple containing:
  • ymean (ndarray) Predicted output values at the test input points.

  • yvar (ndarray): Generally the uncertainty of the fit. For Gaussian Processes this is

the diagonal of the posterior covariance matrix.

Return type:

tuple

pre_predict(Xpred)[source]

Prepares the surrogate for prediction by checking if it is trained and validating the data.

Parameters:

Xpred (ndarray) – (n, d) or (n,) array of input points for prediction

Returns:

Checked input data or default values inferred from training data.

Return type:

ndarray

abstract save_model(path)[source]

Saves the surrogate to a file. The file format can vary between surrogates. As default, the surrogate is saved to ‘base_dir/model_{surrogate_label}.hdf5’.

Parameters:

path (str) – Path including the file name, where the model should be saved.

abstract classmethod load_model(path)[source]

Loads a saved surrogate from a file. The file format can vary between surrogates.

Identifies the surrogate by its class label in the file name.

Parameters:

path (str) – Path including the file name, from where the model should be loaded.

Returns:

Instantiated surrogate model.

Return type:

profit.sur.Surrogate

abstract classmethod from_config(config, base_config)[source]

Instantiates a surrogate based on the parameters given in the configuration file and delegates to child.

Parameters:
  • config (dict) – Only the ‘fit’ part of the base_config.

  • base_config (dict) – The whole configuration parameters.

plot(Xpred=None, independent=None, show=False, ref=None, add_data_variance=True, axes=None)[source]

Simple plotting for dimensions <= 2.

Fore more sophisticated plots use the command ‘profit ui’.

Parameters:
  • Xpred (ndarray) – Prediction points where the fit is plotted. If None, it is inferred from the training points.

  • independent (dict) – Dictionary of independent variables from config.

  • show (bool) – If the figure should be shown directly.

  • ref (ndarray) – Reference function which is fitted.

  • add_data_variance (bool) – Adds the data noise \(\sigma_n^2\) to the prediction variance.

  • axes (matplotlib.pyplot.axes) – Axes object to insert the plot into. If None, a new figure is created.

default_Xpred()[source]

Infer prediction values from training points in each dimension.

Currently a dense grid is created. This becomes inefficient for > 3 dimensions.

Returns:

Prediction points.

Return type:

ndarray