Package mystic :: Module abstract_solver

Module abstract_solver

source code

This module contains the base class for mystic solvers, and describes the mystic solver interface. The "Solve" method must be overwritten with the derived solver's optimization algorithm. In many cases, a minimal function call interface for a derived solver is provided along with the derived class. See `mystic.scipy_optimize`, and the following for an example.

Usage

A typical call to a mystic solver will roughly follow this example:

>>> # the function to be minimized and the initial values
>>> from mystic.models import rosen
>>> x0 = [0.8, 1.2, 0.7]
>>> 
>>> # get monitors and termination condition objects
>>> from mystic.tools import Sow
>>> stepmon = Sow()
>>> evalmon = Sow()
>>> from mystic.termination import CandidateRelativeTolerance as CRT
>>> 
>>> # instantiate and configure the solver
>>> from mystic.scipy_optimize import NelderMeadSimplexSolver
>>> solver = NelderMeadSimplexSolver(len(x0))
>>> solver.SetInitialPoints(x0)
>>> solver.enable_signal_handler()
>>> solver.Solve(rosen, CRT(), EvaluationMonitor=evalmon,
...                            StepMonitor=stepmon)
>>> 
>>> # obtain the solution
>>> solution = solver.Solution()

An equivalent, yet less flexible, call using the minimal interface is:

>>> # the function to be minimized and the initial values
>>> from mystic.models import rosen
>>> x0 = [0.8, 1.2, 0.7]
>>> 
>>> # configure the solver and obtain the solution
>>> from mystic.scipy_optimize import fmin
>>> solution = fmin(rosen,x0)

Handler

All solvers packaged with mystic include a signal handler that provides the following options:

   sol: Print current best solution.
   cont: Continue calculation.
   call: Executes sigint_callback, if provided.
   exit: Exits with current best solution.

Handlers are enabled with the 'enable_signal_handler' method, and are configured through the solver's 'Solve' method. Handlers trigger when a signal interrupt (usually, Ctrl-C) is given while the solver is running.

Classes
  AbstractSolver
AbstractSolver base class for mystic optimizers.