nifty7.minimization.descent_minimizers module

class DescentMinimizer(controller, line_searcher=<nifty7.minimization.line_search.LineSearch object>)[source]

Bases: nifty7.minimization.minimizer.Minimizer

A base class used by gradient methods to find a local minimum.

Descent minimization methods are used to find a local minimum of a scalar function by following a descent direction. This class implements the minimization procedure once a descent direction is known. The descent direction has to be implemented separately.

Parameters
  • controller (IterationController) – Object that decides when to terminate the minimization.

  • line_searcher (callable optional) – Function which infers the step size in the descent direction (default : LineSearch()).

__call__(energy)[source]

Performs the minimization of the provided Energy functional.

Parameters

energy (Energy) – Energy object which provides value, gradient and metric at a specific position in parameter space.

Returns

  • Energy – Latest energy of the minimization.

  • int – Can be controller.CONVERGED or controller.ERROR

Notes

The minimization is stopped if
  • the controller returns controller.CONVERGED or controller.ERROR,

  • a perfectly flat point is reached,

  • according to the line-search the minimum is found,

get_descent_direction(energy, old_value=None)[source]

Calculates the next descent direction.

Parameters
  • energy (Energy) – An instance of the Energy class which shall be minimized. The position of energy is used as the starting point of minimization.

  • old_value (float) – if provided, this must be the value of the energy in the previous step.

Returns

The descent direction.

Return type

Field

reset()[source]
class L_BFGS(controller, line_searcher=<nifty7.minimization.line_search.LineSearch object>, max_history_length=5)[source]

Bases: nifty7.minimization.descent_minimizers.DescentMinimizer

A base class used by gradient methods to find a local minimum.

Descent minimization methods are used to find a local minimum of a scalar function by following a descent direction. This class implements the minimization procedure once a descent direction is known. The descent direction has to be implemented separately.

Parameters
  • controller (IterationController) – Object that decides when to terminate the minimization.

  • line_searcher (callable optional) – Function which infers the step size in the descent direction (default : LineSearch()).

__call__(energy)[source]

Performs the minimization of the provided Energy functional.

Parameters

energy (Energy) – Energy object which provides value, gradient and metric at a specific position in parameter space.

Returns

  • Energy – Latest energy of the minimization.

  • int – Can be controller.CONVERGED or controller.ERROR

Notes

The minimization is stopped if
  • the controller returns controller.CONVERGED or controller.ERROR,

  • a perfectly flat point is reached,

  • according to the line-search the minimum is found,

get_descent_direction(energy, _=None)[source]

Calculates the next descent direction.

Parameters
  • energy (Energy) – An instance of the Energy class which shall be minimized. The position of energy is used as the starting point of minimization.

  • old_value (float) – if provided, this must be the value of the energy in the previous step.

Returns

The descent direction.

Return type

Field

reset()[source]
class NewtonCG(controller, napprox=0, line_searcher=None, name=None, nreset=20, max_cg_iterations=200, energy_reduction_factor=0.1, enable_logging=False)[source]

Bases: nifty7.minimization.descent_minimizers.DescentMinimizer

Calculates the descent direction according to a Newton-CG scheme.

Algorithm derived from SciPy sources.

get_descent_direction(energy, old_value=None)[source]

Calculates the next descent direction.

Parameters
  • energy (Energy) – An instance of the Energy class which shall be minimized. The position of energy is used as the starting point of minimization.

  • old_value (float) – if provided, this must be the value of the energy in the previous step.

Returns

The descent direction.

Return type

Field

property inversion_history
class RelaxedNewton(controller, line_searcher=None)[source]

Bases: nifty7.minimization.descent_minimizers.DescentMinimizer

Calculates the descent direction according to a Newton scheme.

The descent direction is determined by weighting the gradient at the current parameter position with the inverse local metric.

get_descent_direction(energy, _=None)[source]

Calculates the next descent direction.

Parameters
  • energy (Energy) – An instance of the Energy class which shall be minimized. The position of energy is used as the starting point of minimization.

  • old_value (float) – if provided, this must be the value of the energy in the previous step.

Returns

The descent direction.

Return type

Field

class SteepestDescent(controller, line_searcher=<nifty7.minimization.line_search.LineSearch object>)[source]

Bases: nifty7.minimization.descent_minimizers.DescentMinimizer

Implementation of the steepest descent minimization scheme.

Also known as ‘gradient descent’. This algorithm simply follows the functional’s gradient for minimization.

get_descent_direction(energy, _=None)[source]

Calculates the next descent direction.

Parameters
  • energy (Energy) – An instance of the Energy class which shall be minimized. The position of energy is used as the starting point of minimization.

  • old_value (float) – if provided, this must be the value of the energy in the previous step.

Returns

The descent direction.

Return type

Field

class VL_BFGS(controller, line_searcher=<nifty7.minimization.line_search.LineSearch object>, max_history_length=5)[source]

Bases: nifty7.minimization.descent_minimizers.DescentMinimizer

Implementation of the Vector-free L-BFGS minimization scheme.

Find the descent direction by using the inverse Hessian. Instead of storing the whole matrix, it stores only the last few updates, which are used to do operations requiring the inverse Hessian product. The updates are represented in a new basis to optimize the algorithm.

References

W. Chen, Z. Wang, J. Zhou, “Large-scale L-BFGS using MapReduce”, 2014, Microsoft

__call__(energy)[source]

Performs the minimization of the provided Energy functional.

Parameters

energy (Energy) – Energy object which provides value, gradient and metric at a specific position in parameter space.

Returns

  • Energy – Latest energy of the minimization.

  • int – Can be controller.CONVERGED or controller.ERROR

Notes

The minimization is stopped if
  • the controller returns controller.CONVERGED or controller.ERROR,

  • a perfectly flat point is reached,

  • according to the line-search the minimum is found,

get_descent_direction(energy, _=None)[source]

Calculates the next descent direction.

Parameters
  • energy (Energy) – An instance of the Energy class which shall be minimized. The position of energy is used as the starting point of minimization.

  • old_value (float) – if provided, this must be the value of the energy in the previous step.

Returns

The descent direction.

Return type

Field

reset()[source]