nemos.solvers._jaxopt_solvers.JaxoptAdapter#
- class nemos.solvers._jaxopt_solvers.JaxoptAdapter(unregularized_loss, regularizer, regularizer_strength, has_aux, init_params=None, **solver_init_kwargs)[source]#
Bases:
SolverAdapter[JaxoptAdapterState]Base class for adapters wrapping JAXopt-style solvers.
Besides _solver_cls, for proximal solvers the _proximal class variable needs to be set to True.
Attributes
- Parameters:
unregularized_loss (Callable)
regularizer (Regularizer)
regularizer_strength (float | None)
has_aux (bool)
init_params (Params | None)
- __init__(unregularized_loss, regularizer, regularizer_strength, has_aux, init_params=None, **solver_init_kwargs)[source]#
Create the solver.
- Parameters:
unregularized_loss (
Callable) – Unregularized loss function. Currently BaseRegressor.compute_loss.regularizer (
Regularizer) – Regularizer object used to create the penalized loss or get the proximal operator from.has_aux (
bool) – Whether unregularized_loss returns auxiliary variables. If False, the loss function is expected to return a single scalar. If True, the loss is expected to return a tuple of length 2 with a scalar and auxiliary variables.init_params (
Any|None) – Initial model parameters. Passed to the regularizer’s get_proximal_operator or penalized_loss.**solver_init_kwargs – Keyword arguments modifying the solver’s behavior.
Methods
__init__(unregularized_loss, regularizer, ...)Create the solver.
Set of accepted argument names, extended with the wrapped solver's arguments.
init_state(init_params, *args)Initialize the solver state.
run(init_params, *args)Run a full optimization process until a stopping criterion is reached.
stochastic_convergence_criterion(params, ...)Evaluate convergence criterion for stochastic optimization.
stochastic_run(init_params, data_loader, ...)Run optimization over mini-batches from a data loader.
update(params, state, *args)- __getattr__(name)#
Try getting undefined attributes from the underlying solver.
- Parameters:
name (str)
- classmethod __init_subclass__(**kw)#
Generate the docstring including accepted arguments and the wrapped solver’s documentation.
- classmethod get_accepted_arguments()[source]#
Set of accepted argument names, extended with the wrapped solver’s arguments.
- init_state(init_params, *args)[source]#
Initialize the solver state.
Used by
BaseRegressor.initialize_state.
- property maxiter#
- run(init_params, *args)[source]#
Run a full optimization process until a stopping criterion is reached.
Used by
BaseRegressor.fit.
- stochastic_convergence_criterion(params, prev_params, state, prev_state, aux, pass_idx)#
Evaluate convergence criterion for stochastic optimization.
Called once per pass. Subclasses that support stochastic optimization should override this to provide a meaningful default.
- Parameters:
params (
Any) – Parameter values at end of current pass.prev_params (
Any) – Parameter values at end of previous pass.state (
JaxoptAdapterState) – Solver state at end of current pass.prev_state (
JaxoptAdapterState) – Solver state at end of previous pass.aux (
Any) – Auxiliary output from the last batch of the current pass.pass_idx (
int) – Current pass index (0-based).
- Returns:
Trueif optimization should stop.- Return type:
- stochastic_run(init_params, data_loader, n_passes, callback=None, ctx=None)#
Run optimization over mini-batches from a data loader.
- Parameters:
init_params (
Any) – Initial parameter values.data_loader (
DataLoader) – Data loader providing batches and metadata. Must be re-iterable (each__iter__call returns fresh iterator).n_passes (
int) – Number of passes over the data (one pass is what the machine-learning literature calls an epoch). Must be >= 1.callback (
Callback|None) – Training callback. A singleCallbackinstance (useCallbackListfor multiple callbacks). If None, use the no-op base callback.ctx (
TrainingContext|None) – Training context for callback communication. If None, a default context is created.
- Returns:
Final (params, state, aux) tuple.
- Return type:
- Raises:
NotImplementedError – If the solver does not support stochastic optimization.
ValueError – If n_passes < 1.