| TorchOptimizer | R Documentation |
This wraps a torch::torch_optimizer_generator and annotates it with metadata, most importantly a ParamSet.
The optimizer is created for the given parameter values by calling the $generate() method.
This class is usually used to configure the optimizer of a torch learner, e.g.
when constructing a learner or in a ModelDescriptor.
For a list of available optimizers, see mlr3torch_optimizers.
Items from this dictionary can be retrieved using t_opt().
Defined by the constructor argument param_set.
If no parameter set is provided during construction, the parameter set is constructed by creating a parameter
for each argument of the wrapped loss function, where the parameters are then of type ParamUty.
mlr3torch::TorchDescriptor -> TorchOptimizer
new()Creates a new instance of this R6 class.
TorchOptimizer$new( torch_optimizer, param_set = NULL, id = NULL, label = NULL, packages = NULL, man = NULL )
torch_optimizer(torch_optimizer_generator)
The torch optimizer.
param_set(ParamSet or NULL)
The parameter set. If NULL (default) it is inferred from torch_optimizer.
id(character(1))
The id for of the new object.
label(character(1))
Label for the new instance.
packages(character())
The R packages this object depends on.
man(character(1))
String in the format [pkg]::[topic] pointing to a manual page for this object.
The referenced help package can be opened via method $help().
generate()Instantiates the optimizer.
TorchOptimizer$generate(params)
params(named list() of torch_tensors)
The parameters of the network.
torch_optimizer
clone()The objects of this class are cloneable with this method.
TorchOptimizer$clone(deep = FALSE)
deepWhether to make a deep clone.
Other Torch Descriptor:
TorchCallback,
TorchDescriptor,
TorchLoss,
as_torch_callbacks(),
as_torch_loss(),
as_torch_optimizer(),
mlr3torch_losses,
mlr3torch_optimizers,
t_clbk(),
t_loss(),
t_opt()
# Create a new torch optimizer
torch_opt = TorchOptimizer$new(optim_ignite_adam, label = "adam")
torch_opt
# If the param set is not specified, parameters are inferred but are of class ParamUty
torch_opt$param_set
# open the help page of the wrapped optimizer
# torch_opt$help()
# Retrieve an optimizer from the dictionary
torch_opt = t_opt("sgd", lr = 0.1)
torch_opt
torch_opt$param_set
torch_opt$label
torch_opt$id
# Create the optimizer for a network
net = nn_linear(10, 1)
opt = torch_opt$generate(net$parameters)
# is the same as
optim_sgd(net$parameters, lr = 0.1)
# Use in a learner
learner = lrn("regr.mlp", optimizer = t_opt("sgd"))
# The parameters of the optimizer are added to the learner's parameter set
learner$param_set
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.