ott.math.fixed_point_loop.fixpoint_iter#

ott.math.fixed_point_loop.fixpoint_iter(cond_fn, body_fn, min_iterations, max_iterations, inner_iterations, constants, state)[source]#

Implementation of a fixed point loop.

This fixed point loop iterator applies body_fn to a tuple (iteration, constants, state, compute_error) to output a new state, using context provided in iteration and constants.

body_fn is iterated (inner_iterations -1) times, and one last time with the compute_error flag indicating that additional computational effort can be spent on recalculating the latest error (errors are stored as the first element of the state tuple).

upon termination of these inner_iterations, the loop is continued if iteration is smaller than min_iterations, stopped if equal/larger than max_iterations, and interrupted if cond_fn returns False.

Parameters
  • cond_fn (Callable[[int, Any, Any], bool]) – termination condition function

  • body_fn (Callable[[Any, Any, Any, Any], Any]) – body loop instructions

  • min_iterations (int) – lower bound on the total amount of fixed point iterations

  • max_iterations (int) – upper bound on the total amount of fixed point iterations

  • inner_iterations (int) – number of iterations body_fn will be executed successively before calling cond_fn.

  • constants (Any) – constant (during loop) parameters passed on to body

  • state (Any) – state variable

Returns

outputs state returned by body_fn upon termination.