risb.optimize.solver_newton module

Abstract base class for quasi-Newton methods.

class risb.optimize.solver_newton.NewtonSolver(history_size=6, n_restart=inf)[source]

Bases: ABC

Base class for quasi-Newton methods to find the root of a function.

Parameters:
  • history_size (int, optional) – Maximum size of subspace.

  • n_restart (int, optional) – Fully reset subspace after this many iterations.

Notes

update_x() must be defined in the inherited class.

error

History of error vector of x.

Type:

list[numpy.ndarray]

g_x

History of fixed point function with x as the input.

Type:

list[numpy.ndarray]

n

Iteration counter for solver.

Type:

int

solve(fun, x0, args=(), tol=1e-12, maxiter=1000, options=None)[source]

Find the root of a function. It is called similarly to :func:scipy.optimize.root.

Parameters:
  • fun (callable) – The function to find the root of. It must be callable as fun(x, *args).

  • x0 (numpy.ndarray) – Initial guess of the parameters. This does not neccessarily have to be flattened, but it usually is.

  • args (tuple, optional) – Additional arguments to pass to fun.

  • tol (float, optional) – The tolerance. When the 2-norm difference of the return of fun is less than this, the solver stops.

  • maxiter (int, optional) – Maximum number of iterations.

  • options (dict, optional) – keyword arguments to pass to update_x().

Returns:

Root of fun.

Return type:

numpy.ndarray

success

Whether the solver converged to within tolerance.

Type:

bool

abstract update_x(**kwargs)[source]

Return a single iteration for the new guess for x.

Parameters:

**kwargs (dict) – Keyword arguments specific to the solver implementation.

Returns:

New guess for x to add to history.

Return type:

numpy.ndarray

x

History of guesses to the root problem.

Type:

list[numpy.ndarray]