evox.problems.neuroevolution.supervised_learning
#
Module Contents#
Classes#
The supervised learning problem to test a model’s parameters or a batch of parameters with given data and criterion. |
Data#
API#
- evox.problems.neuroevolution.supervised_learning.__all__#
[‘SupervisedLearningProblem’]
- class evox.problems.neuroevolution.supervised_learning.SupervisedLearningProblem(model: torch.nn.Module, data_loader: torch.utils.data.DataLoader, criterion: torch.nn.Module, n_batch_per_eval: int = 1, pop_size: int | None = None, device: torch.device | None = None, reduction: str = 'mean')[source]#
Bases:
evox.core.Problem
The supervised learning problem to test a model’s parameters or a batch of parameters with given data and criterion.
Initialization
Initialize the
SupervisedLearningProblem
.- Parameters:
model – The neural network model whose parameters need to be evaluated.
data_loader – The data loader providing the dataset for evaluation.
criterion – The loss function used to evaluate the parameters’ performance.
n_batch_per_eval – The number of batches to be evaluated in a single evaluation. When set to -1, will go through the whole dataset. Defaults to 1.
pop_size – The size of the population (batch size of the parameters) to be evaluated. Defaults to None for single-run mode.
device – The device to run the computations on. Defaults to the current default device.
reduction – The reduction method for the criterion. ‘mean’ | ‘sum’. Defaults to “mean”.
- Raises:
RuntimeError – If the data loader contains no items.
Warning
This problem does NOT support HPO wrapper (
problems.hpo_wrapper.HPOProblemWrapper
), i.e., the workflow containing this problem CANNOT be vmapped.- _vmap_forward_pass(model_state: Tuple[Dict[str, torch.Tensor], Dict[str, torch.Tensor]], data: Tuple[torch.Tensor, torch.Tensor])[source]#
- _forward_pass(model_state: Tuple[Dict[str, torch.Tensor], Dict[str, torch.Tensor]], data: Tuple[torch.Tensor, torch.Tensor])[source]#
- evaluate(pop_params: Dict[str, torch.nn.Parameter]) torch.Tensor [source]#
Evaluate the fitness of a population (batch) of model parameters.
- Parameters:
pop_params – A dictionary of parameters where each key is a parameter name and each value is a tensor of shape (batch_size, *param_shape) representing the batched parameters of batched models.
- Returns:
A tensor of shape (batch_size,) containing the fitness of each sample in the population.