Changes between Version 1 and Version 2 of DevelopmentIdeas/ModularOptimization

Show
Ignore:
Timestamp:
04/14/07 13:48:47 (6 years ago)
Author:
mforbes
Comment:

Added some discussions

Legend:

Unmodified
Added
Removed
Modified
  • DevelopmentIdeas/ModularOptimization

    v1 v2  
    11= Modular Optimization and Root Finding = 
    22This page contains discussions about a modularized optimization and root finding package. 
    3 [[PageOutline(5,Contents,inline)]] 
     3[[PageOutline(5,Contents,inline)]] (Why does this macro not work to generate the table of contents?) 
    44== Interface == 
     5There should be a very simple interface with default options and methods specified to get code working.  One should then be able to refine the method to suit the particular problem.  Ultimately, it might be nice to provide tools that could try different methods and parameter values to determine the "optimum" solver for a given problem. 
     6 
     7Here is an example of a paradigm where a class is used to return a new functor which returns the zeros of a function 
     8{{{ 
     9#!python 
     10from optimize import Zeros 
     11 
     12def f(x,n): 
     13    """Return x**2 - n.  Zero is at sqrt(n).""" 
     14    return x*x - n 
     15 
     16zeros = Zeros(f=f,x0=0) 
     17 
     18sqrt4 = zeros(4.0) 
     19}}} 
     20The idea here is that the `Zeros` class will perform any initializations (that could be somewhat costly) and checks, then return an optimized function (functor) `zeros` that actually performs the calculation.  The argument `f` could be a simple function or a more complex functor with instructions, for example, about how to compute the Jacobian.  The initializer for the `Zeros` class would query `f` to see its capabilities. 
     21 
     22If you want to use a specific algorithm, then you could specify it at this point.  For example: 
     23{{{ 
     24#!python 
     25from optimize.methods import Broyden 
     26from optimize import Zeros 
     27... 
     28method = Broyden(ftol=1e-10,xtol=1e-12) 
     29zeros = Zeros(f=f,x0=0,method=method) 
     30}}} 
     31`Broyden` would be a convenience wrapper of a modularized optimization method specifying the step type, line search method, etc.  One could also build ones own custom method using the components.  The `Broyden` class should be able to provide a list of options that can easily be selected to customize the method (either by the user or by an automatic performance tuner) as a starting point for a custom optimizer for example.  One could subclass: 
     32{{{ 
     33#!python 
     34from optimize.method import Broyden 
     35from optimize.method.criteria import RelativeValueCriterion 
     36 
     37class MyMethod(Broyden): 
     38    criterion = RelativeValueCriterion 
     39 
     40method = MyMethod 
     41}}} 
     42or one could build from options: 
     43{{{ 
     44#!python 
     45from optimize.method import Broyden 
     46from optimize.method.criteria import RelativeValueCriterion 
     47method = Broyden(criterion=RelativeValueCriterion()) 
     48}}} 
     49It would also be nice if there was a unified method for passing keyword arguments in at various stages, so one could change individual paremeters at any stage, i.e. the tolerance could be specified when constructing the method, or when calling the actual optimizer: 
     50{{{ 
     51#!python 
     52zeros = Zeros(f=f,x0=x0,ftol=0.001) 
     53approx2 = zeros(4.0) 
     54better2 = zeros(4.0,ftol=1e-16) 
     55}}} 
    556=== Calling Conventions === 
    657It would be nice if the calling conventions for each method were as compatible as possible so that it is easy to swap different methods in an out. 
    758==== Arguments ==== 
    859`f` or `func`:: 
    9   Every driver routine will need to specify a function.  Should this argument be called `f` or `func`.  In SciPy, both are used about the same amount.  (P.S. Why does the definition list Wiki syntax work here?) 
     60  Every driver routine will need to specify a function.  Should this argument be called `f` or `func`.  In !SciPy, both are used about the same amount.  (P.S. Why does the definition list Wiki syntax work here?) 
    1061`x0`:: 
    1162  When an initial argument is supplied, the convention seems to be to use `x0`. 
    1263`ftol`, `xtol`, etc.:: 
    1364  These seem to be the convention for specifying tolerances.  The only problem I have with this is that I would like the option of specifying both absolute and relative tolerances.  Perhaps something like `xtol` and `xtol_rel` could be used (absolute tolerances are usually easier to deal with in general). 
     65 
     66== Performance Issues == 
     67The modular approach, with great flexibility in choosing and tuning the optimizer works well for extremely costly functions where the overhead of computing the function is the dominant cost and the goal of the optimizer is to minimize the number of function calls.  It may not be so suitable for functions that are fast: the overhead of python may become significant and the user might be better off using a routine that is coded directly in C or Fortran (for example, if the optimization occurs in the core of a loop).  Hard-coded optimizers, such as already exist in !SciPy should be able to be used with a very similar syntax, however, they will not benefit from the modularity.  This is something to keep in mind.