ScipyOptimizer#

class empulse.optimizers.ScipyOptimizer(method='L-BFGS-B', max_iter=1000, tolerance=None, use_jacobian=True, options=None, **scipy_kwargs)[source]#

General-purpose wrapper around scipy.optimize.minimize.

Supports every method that scipy.optimize.minimize accepts (e.g. 'CG', 'BFGS', 'Newton-CG', 'TNC', 'SLSQP').

When method requires a gradient (use_jacobian=True, the default), the Jacobian is supplied automatically via logit_loss_gradient. For derivative-free methods set use_jacobian=False.

Parameters:
methodstr, default=’L-BFGS-B’

Optimisation method passed to scipy.optimize.minimize.

max_iterint, default=1000

Maximum number of iterations (passed as options['maxiter']).

tolerancefloat or None, default=None

Solver-specific convergence tolerance passed as the tol argument. None uses scipy’s default per-method tolerance.

use_jacobianbool, default=True

If True, pass the analytic gradient to scipy (jac=True). Set to False for derivative-free methods.

optionsdict or None, default=None

Extra entries merged into the options dict passed to scipy. maxiter is always set from max_iter but can be overridden here.

**scipy_kwargs

Additional keyword arguments forwarded verbatim to scipy.optimize.minimize, e.g. bounds=[(min, max), ...] for methods that support bounds.

Examples

from empulse.models import CSLogitClassifier
from empulse.optimizers import ScipyOptimizer

# Use conjugate gradient
model = CSLogitClassifier(optimizer=ScipyOptimizer(method='CG', max_iter=500))

# Use Nelder–Mead (no gradient)
model = CSLogitClassifier(
    optimizer=ScipyOptimizer(method='Nelder-Mead', use_jacobian=False, max_iter=2000)
)
__call__(objective, X, **kwargs)[source]#

Run scipy optimisation.