Anderson Acceleration

class pathsim.optim.anderson.Anderson(m=4, restart=False)[source]

Bases: object

Class for accelerated fixed-point iteration through anderson acceleration. Solves a nonlinear set of equations given in the fixed-point form:

x = g(x)

Anderson Accelerstion tracks the evolution of the solution from the previous iterations. The next step in the iteration is computed as a linear combination of the previous iterates. The coefficients are computed to minimize the least squares error of the fixed-point problem.

Parameters:
  • m (int) – buffer length

  • restart (bool) – clear buffer when full

solve(func, x0, iterations_max=100, tolerance=1e-06)[source]

Solve the function ‘func’ with initial value ‘x0’ up to a certain tolerance.

Note

This method is for testing purposes only and not used in the simulation loop.

Parameters:
  • func (callable) – function to solve

  • x0 (numeric) – starting value for solution

  • iterations_max (int) – maximum number of solver iterations

  • tolerance (float) – convergence condition

Returns:

  • x (numeric) – solution

  • res (float) – residual

  • i (int) – iteration count

reset()[source]

reset the anderson accelerator

step(x, g)[source]

Perform one iteration on the fixed-point solution.

Parameters:
  • x (float, array) – current solution

  • g (float, array) – current evaluation of g(x)

Returns:

  • x (float, array) – new solution

  • res (float) – residual norm, fixed point error

class pathsim.optim.anderson.NewtonAnderson(m=4, restart=False)[source]

Bases: Anderson

Modified class for hybrid anderson acceleration that can use a jacobian ‘jac’ of the function ‘g’ for a newton step before the fixed point step for the initial estimate before applying the anderson acceleration.

If a jacobian ‘jac’ is available, this significantly improves the convergence (speed and robustness) of the solution.

solve(func, x0, jac=None, iterations_max=100, tolerance=1e-06)[source]

Solve the function ‘func’ with initial value ‘x0’ up to a certain tolerance.

Parameters:
  • func (callable) – function to solve

  • x0 (numeric) – starting value for solution

  • jac (callable) – jacobian of ‘func’

  • iterations_max (int) – maximum number of solver iterations

  • tolerance (float) – convergence condition

Note

This method is for testing purposes only and not used in the simulation loop.

Returns:

  • x (numeric) – solution

  • res (float) – residual

  • i (int) – iteration count

step(x, g, jac=None)[source]

Perform one iteration on the fixed-point solution.

If the jacobian of g ‘jac’ is provided, a newton step is performed previous to anderson acceleration.

Parameters:
  • x (float, array) – current solution

  • g (float, array) – current evaluation of g(x)

  • jac (array) – evaluation of jacobian of ‘g’

Returns:

  • x (float, array) – new solution

  • res (float) – residual norm