otaf.surrogate package

Module contents

class otaf.surrogate.NeuralRegressorNetwork(input_dim, output_dim, X, y, clamping=False, finish_critertion_epoch=20, loss_finish=1e-16, metric_finish=0.999, max_epochs=100, batch_size=100, compile_model=True, train_size=0.7, save_path=None, input_description=None, display_progress_disable=True, input_normalization=True, output_normalization=True, noise_dims=[], noise_level=0.1)[source]

Bases: Module

evaluate_model_non_standard_space(x, batch_size=50000, return_on_gpu=False)[source]

Evaluates the model in non-standard space, processing the input in batches.

Parameters:
  • x (array-like or torch.Tensor) – Input data to evaluate.

  • batch_size (int, optional) – Size of batches for evaluation. Default is 50000.

  • return_on_gpu (bool, optional) – Whether to return the result on the GPU. Default is False.

Returns:

The model’s output.

Return type:

torch.Tensor

forward(x)[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

classmethod from_checkpoint(filepath)[source]

Instantiates the network directly from a saved checkpoint, bypassing the need for training data.

get_model_as_openturns_function(batch_size=50000)[source]
get_train_test_data()[source]
gradient(inP)[source]
hessian(inP)[source]
load_model()[source]
pf_monte_carlo_bruteforce(composed_distribution, N_MC_MAX=1000000000, N_GEN_MAX=10000000, batch_size=500000, PF_STAB=1e-06, threshold=0.0)[source]

N_MC_MAX : Monte carlo size N_GEN_MAX : Max sample size to generate PF_STAB : Max variability of probability if one new point is added. threshold : failure threshold

plot_results()[source]
save_model()[source]
train_model()[source]
training_stopping_criterion(epoch)[source]

Determines whether training should stop based on various criteria including: - Minimum loss tolerance. - Gradient changes. - R2 score achievement.

Args: epoch (int): The current epoch number.

Returns: bool: True if training should stop, False otherwise.

otaf.surrogate.add_gaussian_noise(tensor, alpha)[source]

Add Gaussian noise to a tensor.

Parameters:
  • tensor (torch.Tensor) – Input tensor of shape (N, M).

  • alpha (float) – Scaling factor for the standard deviation.

Returns:

Tensor with added Gaussian noise.

Return type:

torch.Tensor

otaf.surrogate.get_base_relu_mlp_model(input_dim, output_dim, compile_model=False)[source]
otaf.surrogate.get_base_tanh_mlp_model(input_dim, output_dim, compile_model=False)[source]
otaf.surrogate.get_custom_mlp_layers(layer_sizes, layer_class=<class 'torch.nn.modules.linear.Linear'>, activation_class=<class 'torch.nn.modules.activation.ReLU'>, layer_kwargs=None, activation_kwargs=None, dropout_class=None, dropout_kwargs=None)[source]

Creates a list of layers for a multi-layer perceptron (MLP) with specified layer sizes, layer class, activation function, and optional dropout layers.

Parameters:
  • layer_sizes (list of int) – List of layer sizes [input, hidden1, …, hiddenN, output].

  • layer_class (callable) – Layer class to use (e.g., nn.Linear).

  • activation_class (callable) – Activation function class to use (e.g., nn.ReLU).

  • layer_kwargs (dict) – Dictionary of additional keyword arguments for the layer class.

  • activation_kwargs (dict) – Dictionary of additional keyword arguments for the activation function class.

  • dropout_prob (float, optional) – Dropout probability. If None, no dropout layers are added.

Returns:

List of layers for the MLP.

Return type:

list

otaf.surrogate.get_variable_size_sequential_linear_model(input_dim, activation=None, relative_max_layer_size=3.0, relative_max_layer_depth=0.25, relative_layer_number=0.5, min_layer_number=4)[source]

Constructs a variable sized neural network models based on input dimensions.

otaf.surrogate.initialize_model_weights(model, init_type='xavier_uniform', init_gain=0.02)[source]

Initialize network weights.

Parameters: model (torch.nn.Module): PyTorch model. init_type (str): The name of an initialization method: ‘normal’, ‘xavier_uniform’, ‘xavier_normal’,

‘kaiming_uniform’, ‘kaiming_normal’, ‘orthogonal’, ‘uniform’.

init_gain (float): Scaling factor for normal, xavier and orthogonal.