Commit 2108f67d authored by Artem Pulkin's avatar Artem Pulkin

ml_util: add a handle for (re)-initializing optimizes in closure

parent 23ffc7eb
Pipeline #44299 passed with stage
in 2 minutes and 28 seconds
......@@ -502,11 +502,36 @@ class SimpleClosure:
self.loss_function = loss_function
self.dataset = dataset
self.criterion = criterion
self.optimizer = optimizer(self.learning_parameters(), **optimizer_kwargs)
self.__optimizer__ = optimizer
self.__optimizer_kwargs__ = optimizer_kwargs
self.optimizer = self.optimizer_init()
self.loss_function_kwargs = loss_function_kwargs
self.last_loss = None
def optimizer_init(self, optimizer=None, **kwargs):
"""
Initialize the optimizer.
Parameters
----------
optimizer
Optimizer class.
kwargs
Arguments to the constructor.
Returns
-------
optimizer
The resulting optimizer object.
"""
if optimizer is None:
optimizer = self.__optimizer__
opt_args = self.__optimizer_kwargs__.copy()
opt_args.update(kwargs)
self.optimizer = optimizer(self.learning_parameters(), **opt_args)
return self.optimizer
def learning_parameters(self):
"""
Learning parameters.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment