codes.surrogates.FCNN package#

Submodules#

codes.surrogates.FCNN.fcnn module#

class codes.surrogates.FCNN.fcnn.FCFlatBatchIterable(inputs_t, targets_t, batch_size, shuffle)#

Bases: IterableDataset

class codes.surrogates.FCNN.fcnn.FullyConnected(device=None, n_quantities=29, n_timesteps=100, n_parameters=0, training_id=None, config=None)#

Bases: AbstractSurrogateModel

create_dataloader(data, timesteps, batch_size, shuffle, dataset_params, num_workers=0, pin_memory=True)#

Build CPU tensors once and yield shuffled batches each epoch. data: (n_samples, n_timesteps, n_quantities) inputs = [initial_state, time, (params?)] targets = state_at_time

epoch(data_loader, criterion, optimizer)#
Return type:

None

fit(train_loader, test_loader, epochs, position=0, description='Training FullyConnected', multi_objective=False)#

Train the FullyConnected model.

Parameters:
  • train_loader (DataLoader) – The DataLoader object containing the training data.

  • test_loader (DataLoader) – The DataLoader object containing the test data.

  • epochs (int) – The number of epochs to train the model.

  • position (int) – The position of the progress bar.

  • description (str) – The description for the progress bar.

  • multi_objective (bool) – Whether multi-objective optimization is used. If True, trial.report is not used (not supported by Optuna).

Return type:

None

Returns:

None. The training loss, test loss, and MAE are stored in the model.

forward(inputs)#

Forward pass for the FullyConnected model.

Parameters:

inputs (tuple) – (x, targets) - ‘targets’ is included for a consistent interface

Return type:

Tensor

Returns:

(outputs, targets)

forward_from_state(state, times, params=None)#

Predict the states at several time inputs from one initial state.

Packs [state, time, params] as create_dataloader does. See AbstractSurrogateModel.forward_from_state.

Return type:

Tensor

prepare_data(dataset_train, dataset_test, dataset_val, timesteps, batch_size, shuffle=True, dummy_timesteps=True, dataset_train_params=None, dataset_test_params=None, dataset_val_params=None)#

Prepare the data for training, testing, and validation. This method should return the DataLoader objects for the training, testing, and validation data.

Parameters:
  • dataset_train (ndarray) – The training dataset.

  • dataset_test (ndarray | None) – The testing dataset.

  • dataset_val (ndarray | None) – The validation dataset.

  • timesteps (ndarray) – The timesteps.

  • batch_size (int) – The batch size.

  • shuffle (bool) – Whether to shuffle the data.

  • dummy_timesteps (bool) – Whether to use dummy timesteps. Defaults to True.

Returns:

The DataLoader objects for the

training, testing, and validation data.

Return type:

tuple[DataLoader, DataLoader, DataLoader]

class codes.surrogates.FCNN.fcnn.FullyConnectedNet(input_size, hidden_size, output_size, num_hidden_layers, activation=ReLU())#

Bases: Module

forward(inputs)#

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.

Return type:

Tensor

class codes.surrogates.FCNN.fcnn.FullyConnectedResidual(device=None, n_quantities=29, n_timesteps=100, n_parameters=0, training_id=None, config=None)#

Bases: FullyConnected

FullyConnected variant that predicts the change from the initial state.

The network output is added to the initial state, so it only has to learn the deviation from it. Everything downstream still sees absolute states.

forward(inputs)#

Forward pass for the FullyConnected model.

Parameters:

inputs (tuple) – (x, targets) - ‘targets’ is included for a consistent interface

Return type:

Tensor

Returns:

(outputs, targets)

codes.surrogates.FCNN.fcnn_config module#

class codes.surrogates.FCNN.fcnn_config.FCNNBaseConfig(learning_rate=0.0003, regularization_factor=0.0, optimizer='adamw', momentum=0.0, scheduler='cosine', poly_power=0.9, eta_min=0.1, activation=None, loss_function=None, beta=1.0, gradient_clip=0.0, hidden_size=150, num_hidden_layers=5)#

Bases: AbstractSurrogateBaseConfig

Configuration for the Fully Connected Neural Network (FCNN) surrogate model.

This config defines the structure and training settings for a standard MLP-style surrogate model with fully connected layers.

Attributes:
  • hidden_size (int) – Number of neurons per hidden layer.

  • num_hidden_layers (int) – Number of hidden layers in the network.

hidden_size: int = 150#
num_hidden_layers: int = 5#

Module contents#