SupervisedSolverInterface#
- class SupervisedSolverInterface(loss=None, **kwargs)[source]#
Bases:
SolverInterface
Base class for Supervised solvers. This class implements a Supervised Solver , using a user specified
model
to solve a specificproblem
.The
SupervisedSolverInterface
class can be used to define Supervised solvers that work with one or multiple optimizers and/or models. By default, it is compatible with problems defined byAbstractProblem
, and users can choose the problem type the solver is meant to address.Initialization of the
SupervisedSolver
class.- Parameters:
problem (AbstractProblem) – The problem to be solved.
loss (torch.nn.Module) – The loss function to be minimized. If
None
, thetorch.nn.MSELoss
loss is used. Default isNone
.kwargs – Additional keyword arguments to be passed to the
SolverInterface
class.
- accepted_conditions_types#
alias of
InputTargetCondition
- optimization_cycle(batch)[source]#
The optimization cycle for the solvers.
- Parameters:
batch (list[tuple[str, dict]]) – A batch of data. Each element is a tuple containing a condition name and a dictionary of points.
- Returns:
The losses computed for all conditions in the batch, casted to a subclass of
torch.Tensor
. It should return a dict containing the condition name and the associated scalar loss.- Return type:
- abstract loss_data(input, target)[source]#
Compute the data loss for the Supervised. This method is abstract and should be override by derived classes.
- Parameters:
input (LabelTensor | torch.Tensor | Graph | Data) – The input to the neural network.
target (LabelTensor | torch.Tensor | Graph | Data) – The target to compare with the network’s output.
- Returns:
The supervised loss, averaged over the number of observations.
- Return type:
LabelTensor | torch.Tensor | Graph | Data
- property loss#
The loss function to be minimized.
- Returns:
The loss function to be minimized.
- Return type: