clipppy.commands.fit¶
Module Contents¶
- class clipppy.commands.fit.Fit(**kwargs)¶
Fit using ELBO maximisation.
- avgwindow :int = 100¶
Number of most recents steps to use for calculating various averaged quantities (average rate, mean loss…).
- callback :Callable[[int, float, Mapping[str, Any]], Any]¶
Callback to be executed after each step.
Signature should be
callback(i, loss, locals), whereiis the current step index,lossis the current loss, andlocalsis a dictionary of the local variables in the fitting function. Depending on the python implementation, modifying its values might influence the fitting. Returning anyTruevalue interrupts the fitting.
- conv_th :float¶
Convergence threshold. Should be positive or
-float('inf')to turn off convergence-based termination.See
converged.
- loss_args :Mapping¶
Arguments for the
loss_clsconstructor.Pass the special value
Command.no_callto avoid instantiatingload_clsand use it directly.
- loss_cls :Union[Type[pyro.infer.ELBO], Callable[Ellipsis, torch.Tensor]]¶
The loss class to instantiate.
- lr :float = 0.001¶
Learning rate (passed to the optimizer).
- min_steps :int = 1¶
Run at least
min_stepssteps.
- n_steps :int = 1000¶
Run at most
n_stepssteps.
- n_write :int¶
Save the guide each
n_writesteps.
- optimizer_args :Optional[Mapping]¶
The (keyword!) arguments to pass to
optimizer_cls.Will be updated with the standalone
lrpassed, unless it isnoop.Pass the special value
Command.no_callto avoid instantiatingoptimizer_clsand use it directly.
- optimizer_cls :Union[Type[pyro.optim.PyroOptim], Callable[[Mapping], pyro.optim.PyroOptim]]¶
The class of
PyroOptimto instantiate (or a function that acts like it).
- converged(self, slope: float, windowed_losses: Iterable[float] = None)¶
Indicate whether the fit is considered converged.
This implementation returns
Trueif the averaged slopeslope, defined as the fitted slope of losses over the lastavgwindowiterations, divided by the learning rate, is shallower thanconv_th, which should be given as positive. If theslopeis positive, this will always be true, so turning this check off requires settingconv_th = -float('inf').This method can be overridden in subclasses to provide more sophisticated checks.
- forward(self, model: clipppy.utils.typing._Model, guide: clipppy.utils.typing._Guide, *args, **kwargs)¶
- property lossfunc(self) Union[pyro.infer.ELBO, Callable[Ellipsis, torch.Tensor]]¶
Construct a loss as
loss_cls(**loss_args)or simply returnloss_clsifloss_argsisCommand.no_call.
- property optimizer(self) pyro.optim.PyroOptim¶
Construct an optimizer as
optimizer_cls(optimizer_args)or simply returnoptimizer_clsifoptimizer_argsisCommand.no_call.