core.experiment.ExperimentControl

core.experiment.ExperimentControl(
    dataset,
    model_class,
    hyperparameters,
    seed=123,
    device='cpu',
    num_workers=0,
    epochs=None,
    batch_size=32,
    optimizer_class=None,
    loss_function=None,
    metrics=list(),
    n_initial=10,
    max_evals=50,
    experiment_name='default_experiment',
    verbosity=0,
)

Controls the experiment configuration.

This data class serves as the central configuration object for optimization experiments, holding the dataset, model configuration, hyperparameters, and other settings.

Attributes

Name Type Description
dataset SpotDataSet The dataset object containing the data.
model_class Any The class of the model to be instantiated.
hyperparameters Any The hyperparameters for the model.
seed int The random seed for reproducibility.
device str The device to run the model on (e.g. “cpu” or “cuda”).
num_workers int The number of workers to use for data loading.
epochs Optional[int] The number of epochs to train the model.
batch_size int The batch size for training.
optimizer_class Optional[Any] The optimizer class to use for training.
loss_function Optional[Any] The loss function to use for training.
metrics List[str] The metrics to track during training.
n_initial int The number of initial design points.
max_evals int The maximum number of evaluations.
experiment_name str The name of the experiment.
verbosity int The verbosity level.

Public Methods

to_dict(): Convert the object to a dictionary. torch_device(): Return the torch device object.

Examples

import numpy as np
import torch
from spotoptim.core.data import SpotDataFromArray
from spotoptim.core.experiment import ExperimentControl
from spotoptim.nn.mlp import MLP

# 1. Prepare Data
X = np.array([[0.1, 0.2], [0.3, 0.4]])
y = np.array([[1.0], [2.0]])
dataset = SpotDataFromArray(x_train=X, y_train=y)

# 2. Define Hyperparameters
params = {"l1": 16, "num_hidden_layers": 1, "lr": 1e-3}

# 3. Initialize Control with Real Model
exp = ExperimentControl(
    dataset=dataset,
    model_class=MLP,
    hyperparameters=params,
    experiment_name="real_model_run",
    seed=42
)
print(exp.to_dict())
{'dataset': <spotoptim.core.data.SpotDataFromArray object at 0x11fc4c050>, 'model_class': <class 'spotoptim.nn.mlp.MLP'>, 'hyperparameters': {'l1': 16, 'num_hidden_layers': 1, 'lr': 0.001}, 'seed': 42, 'device': 'cpu', 'num_workers': 0, 'epochs': None, 'batch_size': 32, 'optimizer_class': None, 'loss_function': None, 'metrics': [], 'n_initial': 10, 'max_evals': 50, 'experiment_name': 'real_model_run', 'verbosity': 0}

Methods

Name Description
to_dict Convert to dictionary for partial backward compatibility or logging.

to_dict

core.experiment.ExperimentControl.to_dict()

Convert to dictionary for partial backward compatibility or logging.

Returns

Name Type Description
Dict[str, Any] Dict[str, Any]: Dictionary representation of the object.

Examples

import numpy as np
from spotoptim.core.data import SpotDataFromArray
from spotoptim.core.experiment import ExperimentControl

# Setup
dataset = SpotDataFromArray(np.zeros((5,2)), np.zeros((5,1)))
exp = ExperimentControl(dataset, model_class=None, hyperparameters={})

# Convert to dict
config = exp.to_dict()
print(config['seed'])
123