profit.sur.ann.artificial_neural_network

Module Contents

Classes

ANN

Base class for all surrogate models.

ANNSurrogate

Base class for all surrogate models.

Autoencoder

Nonlinear autoencoder with activation functions

class profit.sur.ann.artificial_neural_network.ANN(config)

Bases: profit.sur.sur.Surrogate, abc.ABC

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’: {}}]

_defaults
train(X, y)

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.

predict(Xpred)

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

save_model(path)

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.

classmethod load_model(path)

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

classmethod from_config(config, base_config)

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.

classmethod handle_subconfig(config, base_config)
class profit.sur.ann.artificial_neural_network.ANNSurrogate

Bases: profit.sur.sur.Surrogate

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’: {}}]

train(x, y)

Fits a artificial neural network to input points x and model outputs y with scale sigma_f and noise sigma_n

abstract add_training_data(x, y, sigma=None)

Adds input points x and model outputs y with std. deviation sigma and updates the inverted covariance matrix for the GP via the Sherman-Morrison-Woodbury formula

predict(x)

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

class profit.sur.ann.artificial_neural_network.Autoencoder(D, d)

Bases: profit.sur.sur.Surrogate, torch.nn.Module

Nonlinear autoencoder with activation functions

forward(x)
train(x, learning_rate=0.01, nstep=1000)

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.