PyTorch MLP and LinearRegressor for building objective functions and surrogates.
spotoptim provides two PyTorch neural network modules in spotoptim.nn: MLP (multi-layer perceptron) and LinearRegressor (configurable regression network). Both serve as building blocks for surrogate models and objective functions in hyperparameter tuning workflows.
MLP
MLP is a torch.nn.Sequential subclass that builds a multi-layer perceptron with configurable width, depth, activation, and dropout.
The architecture can be specified in two ways:
Explicit: pass a hidden_channels list where each element is a layer size and the last element is the output dimension.
Compact: pass l1 (neurons per hidden layer), num_hidden_layers, and output_dim. Internally this is converted to hidden_channels = [l1] * num_hidden_layers + [output_dim].
MLP.get_default_parameters() returns a ParameterSet with sensible bounds for l1, num_hidden_layers, activation, lr, and optimizer. This is the starting point when tuning an MLP with SpotOptim.
from spotoptim.nn import MLPparams = MLP.get_default_parameters()print(f"Parameter names: {params.names()}")
See Hyperparameter Sets for details on modifying parameter bounds and types.
LinearRegressor
LinearRegressor is a torch.nn.Module for regression tasks. With num_hidden_layers=0 it performs pure linear regression; with one or more hidden layers it becomes a deep network with a configurable activation function.
Both MLP and LinearRegressor expose a get_optimizer method that maps a string name to the corresponding torch.optim class. An internal map_lr function translates a unified learning-rate multiplier to optimizer-specific defaults (e.g., \(\text{lr}=1.0\) maps to \(0.001\) for Adam and \(0.01\) for SGD).
Beyond standard PyTorch optimizers, spotoptim bundles AdamWScheduleFree from spotoptim.optimizer.schedule_free, a schedule-free variant of AdamW that does not require a learning-rate scheduler.
MLP and LinearRegressor are the network backbones used inside TorchObjective-based optimization workflows. In a typical setup:
A network class (e.g., LinearRegressor) defines the architecture.
A TorchObjective wraps training and evaluation into a single callable that SpotOptim treats as its black-box objective.
SpotOptim tunes hyperparameters (l1, num_hidden_layers, lr, optimizer, activation) using a surrogate model such as MLPSurrogate or Kriging.
The dataset loaders in Data provide ready-made datasets for this workflow, and the Hyperparameter Sets page explains how to customize parameter bounds for tuning.