saealib.TorchSurrogate#
- class saealib.TorchSurrogate(model, optimizer_cls=None, optimizer_kwargs=None, loss_fn=None, epochs=100)[ソース]#
ベースクラス:
RegressionSurrogateSurrogate adapter for PyTorch
nn.Modulemodels.Wraps any
torch.nn.Modulethat maps(n_samples, n_features)to(n_samples, n_obj). The model is trained from scratch on eachfitcall by resetting to the weights captured at construction time, so this adapter is safe to use withLocalSurrogateManager(which re-fits per candidate).- パラメータ:
model (torch.nn.Module) -- Neural network model. Its output shape must be
(n_samples, n_obj).optimizer_cls (type or None) -- Optimizer class (e.g.
torch.optim.Adam). Defaults totorch.optim.Adam.optimizer_kwargs (dict or None) -- Keyword arguments forwarded to the optimizer constructor. Defaults to
{}.loss_fn (callable or None) -- Loss function. Defaults to
torch.nn.MSELoss().epochs (int) -- Number of training epochs per
fitcall. Default: 100.
- 例外:
ImportError -- If PyTorch is not installed.
Methods
Return the surrogate model contract. |
|
Fit the surrogate model. |
|
Post-fit lifecycle hook; override to inject custom processing. |
|
Predict using the surrogate model. |
|
Return a copy of this surrogate with |
Method Details
- TorchSurrogate.__init__(model, optimizer_cls=None, optimizer_kwargs=None, loss_fn=None, epochs=100)[ソース]#
- パラメータ:
model (torch.nn.Module)
optimizer_cls (type | None)
optimizer_kwargs (dict | None)
loss_fn (Callable[..., Any] | None)
epochs (int)
- 戻り値の型:
None
- TorchSurrogate.contract()#
Return the surrogate model contract.
- 戻り値の型:
- TorchSurrogate.fit(train_x, train_y)[ソース]#
Fit the surrogate model.
Resets model weights to their initial values before training.
- パラメータ:
train_x (np.ndarray) -- Training input data. shape: (n_samples, n_features)
train_y (np.ndarray) -- Training output data. shape: (n_samples, n_obj) or (n_samples,).
- 戻り値の型:
None
- TorchSurrogate.post_fit(train_x, train_y, ctx=None)#
Post-fit lifecycle hook; override to inject custom processing.
- パラメータ:
train_x (np.ndarray) -- Training input data used for this fit. shape: (n_samples, n_features)
train_y (np.ndarray) -- Training output data used for this fit. shape: (n_samples, n_obj)
ctx (OptimizationState or None, optional) -- Current optimization context.
- 戻り値の型:
None