Changeset 133


Ignore:
Timestamp:
04/02/09 23:48:59 (7 years ago)
Author:
mmckerns
Message:

merged changes from mystic-0.1a1 release branch back into trunk
(reorganized examples; moved/edited READMEs)

Location:
mystic
Files:
1 added
2 deleted
6 edited
1 copied
11 moved

Legend:

Unmodified
Added
Removed
  • mystic/examples/Make.mm

    r127 r133  
    2525#EXPORT_PYTHON_MODULES = \ 
    2626EXPORT_BINS = \ 
    27     test_br8.py \ 
    28 #   gplot_test_ffit.py \ 
    29     test_ffit.py \ 
    30     test_ffit2.py \ 
    31     test_ffitB.py \ 
    32     test_ffitC.py \ 
    33     test_ffitD.py \ 
    34     scipy_ffit.py \ 
    35     test_fosc3d.py \ 
    36     test_griewangk.py \ 
    37     test_dejong3.py \ 
    38     test_dejong4.py \ 
    39     test_dejong5.py \ 
    40     test_corana.py \ 
    41 #   sam_corana.py \ 
    42 #   sam_corana2.py \ 
    43     mpl_corana.py \ 
    44     test_rosenbrock.py \ 
    45     test_rosenbrock2.py \ 
    46     test_rosenbrock3.py \ 
    47 #   sam_rosenbrock.py \ 
    4827    cg_rosenbrock.py \ 
    49 #   sam_cg_rosenbrock.py \ 
    50     test_zimmermann.py \ 
    51 #   sam_zimmermann.py \ 
    52 #   sam_cg_zimmermann.py \ 
    53     test_lorentzian.py \ 
    54     test_lorentzian2.py \ 
    55 #   sam_mogi.py \ 
    56     test_mogi.py \ 
    57     test_mogi2.py \ 
    58 ##  test_mogi3.py \ 
    59 ##  test_mogi4.py \ 
    60     test_mogi_anneal.py \ 
    61     test_mogi_leastsq.py \ 
    62 #   sam_circle_matlab.py \ 
    63     test_circle.py \ 
    64 #   qld_circle_dual.py \ 
    65 ##  metropolis.py \ 
    66 ##  test_twistedgaussian.py \ 
    67 ##  test_twistedgaussian2.py \ 
    68 ##  test_twistedgaussian3.py \ 
    69     test_wavy.py \ 
    7028##  derun.py \ 
    7129##  dummy.py \ 
    72     test_getCost.py \ 
    73     forward_model.py \ 
    74     rosetta_parabola.py \ 
    75     rosetta_mogi.py \ 
    7630    example01.py \ 
    7731    example02.py \ 
     
    8640    example11.py \ 
    8741    example12.py \ 
     42    forward_model.py \ 
     43#   gplot_test_ffit.py \ 
     44##  metropolis.py \ 
     45    mpl_corana.py \ 
     46    rosetta_parabola.py \ 
     47    rosetta_mogi.py \ 
     48    test_br8.py \ 
     49    test_circle.py \ 
     50    test_corana.py \ 
     51    test_dejong3.py \ 
     52    test_dejong4.py \ 
     53    test_dejong5.py \ 
     54    test_ffit.py \ 
     55    test_ffit2.py \ 
     56    test_ffitB.py \ 
     57    test_ffitC.py \ 
     58    test_ffitD.py \ 
     59    test_fosc3d.py \ 
     60    test_getCost.py \ 
     61    test_griewangk.py \ 
     62    test_lorentzian.py \ 
     63    test_lorentzian2.py \ 
     64    test_mogi.py \ 
     65    test_mogi2.py \ 
     66##  test_mogi3.py \ 
     67##  test_mogi4.py \ 
     68    test_mogi_anneal.py \ 
     69    test_mogi_leastsq.py \ 
     70    test_rosenbrock.py \ 
     71    test_rosenbrock2.py \ 
     72    test_rosenbrock3.py \ 
     73##  test_twistedgaussian.py \ 
     74##  test_twistedgaussian2.py \ 
     75##  test_twistedgaussian3.py \ 
     76    test_wavy.py \ 
     77    test_zimmermann.py \ 
    8878 
    8979 
  • mystic/examples/NOTES

    r127 r133  
    1 Model-independent optimization framework 
    2  - optimizer utilizes a 'function' interface (i.e. scipy.optimize.fmin()) 
    3  - optimizer can be selected at runtime 
    4  - cost function can be provided at runtime 
    5  - results monitoring 
    6  - job interrupt & steering 
    7  - allow 'configuration' modification (i.e. constraints, optimizers, etc) 
    8  - parallel/distributed job submission 
    9  
    10 Examples: (o = Demo; * = Code-only) 
    11  o Model study: test_ffit and/or test_fosc3d 
    12  
    13  o mystic.derun => an optimization framework pyre application [NEEDS WORK!] 
    14  * mystic.dummy => Chebyshev8 cost function 
    15  
    16  * mystic.differential_evolution => Price & Storn's DE solver 
    17    - solver.Solution() 
    18    - solver.Solve(...) 
    19      . extra args (i.e. constants, constraints?) 
    20      . monitors 
    21      . callback 
    22      . handler 
    23  o Handler example: test_mogi2 and/or test_ffit  
    24  * mystic.termination => termination conditions 
    25  * mystic.strategy => mutation strategies (liga ?) 
    26  * mystic.tools 
    27    - Sow() 
    28    - wrap_function() (adds monitor.  similarly add constraints?) 
    29  
    30  * mystic.nelder_mead => adapted from scipy, now has mystic 'solver interface' 
    31  o Comparison study: (branches/ooe-tests) test_circle and/or test_mogi 
    32  
    33  * mystic.forward_model => tools to build cost function "on-the-fly" 
    34    - builder.CostFactory() 
    35      . factory.addModel() 
    36      . factory.getCostFunction[Slow]() 
    37  o mystic.test_getCost => example usage of CostFactory [NEEDS WORK!] 
    38    - SIMPLE example: User-prepared cost function 
    39    - SIMPLE example: CostFactory-built cost function 
    40    def f(p): 
    41      a,b,c = p 
    42      def g(x): 
    43        return a*x*x + b*x + c*x 
    44      return g 
     1#!/usr/bin/env python 
     2#----------------------------------------------------------------------------- 
     3# Model Factory Interface: 
     4"""NOTES: 
     5- forward model "forward_poly" calculates a function of x (w/ fixed a,b,c) 
     6- ForwardPolyFactory is a "function generator", allowing a,b,c to be set 
     7""" 
     8def ForwardPolyFactory(params): 
     9    a,b,c = params 
     10    def forward_poly(x): 
     11        """ x should be a 1D (1 by N) numpy array """ 
     12        return array((a*x*x + b*x + c)) 
     13    return forward_poly 
    4514 
    4615 
    47  o Parallel example: test_lorentzian2 
    48    REMEMBER: mpd & 
    4916 
    50    mpi_differential_evolution.py or parallel_desolve.py => mpi job manager 
    51    parallel_map2.py => parallel mapping using mpi directives 
    5217 
     18 
     19 
     20 
     21 
     22 
     23 
     24 
     25#----------------------------------------------------------------------------- 
     26# Forward Model Invocation: 
     27"""NOTES: 
     28- fwd is a instance of "forward_poly", built with chosen a,b,c  
     29- "data" converts a function of x into a function of a,b,c (w/ fixed x) [i.e. a functor] 
     30- same methodology is used in COST FUNCTION to produce "goodness of fit" 
     31""" 
     32def data(params): 
     33    fwd = ForwardPolyFactory(params) 
     34    x = (array([range(101)])-50.)[0] 
     35    return fwd(x) 
     36 
     37 
     38 
     39 
     40 
     41 
     42 
     43 
     44 
     45 
     46 
     47#----------------------------------------------------------------------------- 
     48# Build "Measured" Data: (optional... use real measured data) 
     49"""NOTES: 
     50- target is "target solution" for a,b,c 
     51- data is used to generate "measured data" (parameters a,b,c = target) 
     52""" 
     53target = [1., 2., 1.] 
     54datapts = data(target) 
     55 
     56 
     57 
     58 
     59 
     60 
     61 
     62 
     63 
     64 
     65 
     66 
     67 
     68 
     69 
     70#----------------------------------------------------------------------------- 
     71# Cost Function Generation: (optional... write your cost function explicitly) 
     72"""NOTES: 
     73- F is an instance of Cost Function (goodness of fit) generator  
     74- myCost is an instance of a Cost Function 
     75- (default metric) calculates the LeastSquared difference for fwd(x) & datapts 
     76""" 
     77x = (array([range(101)])-50.)[0] 
     78F = CostFactory() 
     79F.addModel(ForwardPolyFactory,'poly',3) 
     80myCost = F.getCostFunction(evalpts=x, observations=datapts) 
     81 
     82 
     83 
     84 
     85 
     86 
     87 
     88 
     89 
     90 
     91 
     92 
     93#----------------------------------------------------------------------------- 
     94# Call to Solver: 
     95"""NOTES: 
     96- solution is set of solved parameters a,b,c 
     97- stepmon holds a log of optimization steps 
     98""" 
     99solution, stepmon = de_solve(myCost) 
     100 
     101 
     102 
     103 
     104 
     105 
     106#----------------------------------------------------------------------------- 
     107ND = 3 
     108NP = 80 
     109MAX_GENERATIONS = ND*NP 
     110#----------------------------------------------------------------------------- 
     111# Standard "Solver" Configuration: 
     112"""NOTES: 
     113- ND is number of parameters (a,b,c) 
     114- NP is size of trial population 
     115- MAX_GENERATIONS is maximum optimization iterations 
     116#----------------------------------------------------------------------------- 
     117- VerboseSow logs/prints "goodness of fit" and "best solution" at each step 
     118- minrange/maxrange provide box constraints (for parameters a,b,c) 
     119- SetRandomInitialPoints chooses an initial solution within box constraints 
     120- SetStrictRanges only allows trial solutions within box constraints 
     121- 'termination' conditions are to end when "no change" after 300 generations 
     122- enable_signal_handler allows "interrupt" signal to be caught 
     123- sigint_callback registers a user-provided function to the signal_handler 
     124""" 
     125def de_solve(CF): 
     126    solver = DifferentialEvolutionSolver(ND, NP) 
     127    solver.enable_signal_handler() 
     128 
     129    stepmon = VerboseSow(10,50) 
     130    minrange = [-100., -100., -100.]; maxrange = [100., 100., 100.]; 
     131    solver.SetRandomInitialPoints(min = minrange, max = maxrange) 
     132    solver.SetStrictRanges(min = minrange, max = maxrange) 
     133    solver.SetEvaluationLimits(maxiter=MAX_GENERATIONS) 
     134 
     135    solver.Solve(CF,termination=ChangeOverGeneration(generations=300),\ 
     136                 CrossProbability=0.5,ScalingFactor=0.5,\ 
     137                 StepMonitor=stepmon,sigint_callback=plot_sol) 
     138 
     139    solution = solver.Solution() 
     140    return solution, stepmon 
     141#----------------------------------------------------------------------------- 
     142# BONUS... the Callback Function: 
     143"""NOTES: 
     144- called on "catch" of signal-interrupt 
     145- _MUST_ be a function of "params" 
     146- _only_one_ configuration parameter is (currently) allowed 
     147""" 
     148def plot_sol(params,linestyle='b-'): 
     149    x = (array([range(101)])-50.)[0] 
     150    d = data(params) 
     151    pylab.plot(x,d,'%s'%linestyle,linewidth=2.0) 
     152    pylab.axis(plotview) 
     153    return 
     154 
     155 
     156 
     157 
     158 
     159 
     160 
     161 
     162 
     163 
     164# DONE 
  • mystic/examples/README

    r127 r133  
    1 == Notes on mystic and pyina examples == 
     1== Notes on mystic examples == 
     2NOTE: for all examples that use matplotlib, please use the TKAgg backend. 
     3Thus, run the examples like this:  "python example04.py -dTKAgg" 
     4(see ticket #36 for more details). 
    25 
    36Dependencies: 
    4  - All examples with prefix "example" should run without new dependencies, and are intended as a tutorial. (i.e. TRY THESE FIRST) 
     7 - All examples with prefix "example" should run without new dependencies, and are intended as a tutorial (i.e. TRY THESE FIRST). 
    58 - All examples with prefix "test_" should run without new dependencies. 
    6  - All examples with prefix "scipy_" requires scipy to be installed. (tested on version 0.4.8). 
    7  - All examples with prefix "sam_" requires "sam" and "scipy" to be installed.  
    8  - All examples with prefix "cg_" requires "sam" and "scipy" to be installed. It tries a few of the test problems with conjugate gradient method (which finds local minima). 
    99 - All examples with prefix "gplot_" requres gnuplot-py to be installed. 
     10 
     11Exceptions to the rule: 
     12 - The following examples also require scipy to be installed. (tested on version 0.4.8 and 0.7.0): 
     13    . cg_rosenbrock.py 
     14    . test_br8.py 
     15    . test_lorentzian.py 
     16    . test_mogi.py 
     17    . test_mogi_anneal.py, 
     18    . test_mogi_leastsq.py 
     19    . test_twistedgaussian.py 
     20    . test_twistedgaussian2.py 
    1021 
    1122Special examples: 
    1223 - All examples with prefix "rosetta_" require park to be installed. (tests on version park-1.2).  Run with "--park" to execute with park. See "--help" for more options. 
     24 - The derun.py example requires pyre (from pythia-0.8) to be installed, and drives the otherwise useless 'dummy.py'. 
    1325 
    1426 
    15 Additional egg for Mathematica Users: 
    16  - mystic.nb: The mathematica notebook with most of the test functions used. 
    17  
     27------------------------------------------------------------------------------- 
    1828 
    1929Notes on the "ffit" tests/examples: 
     
    3646 
    3747 
    38 Notes on other examples: 
    39  - CubeSection.py requires VTK + Tkinter. Helps visualize the process of finding the biggest square inside a unit cube. 
    40  
    41  
    42 adapted from pyina CVS 2008-07-07 
    43  
    4448# end of file 
  • mystic/examples/cg_rosenbrock.py

    r88 r133  
    3535          c[i,j] = rosen([xx,yy]) 
    3636 
    37     #sam.eval("[c,h]=contourf(X,Y,C,60);set(h,'EdgeColor','none')") 
    3837    pylab.contourf(x,y,log(c*20+1)+2,60) 
    3938    show() 
  • mystic/examples/test_mogi2.py

    r117 r133  
    4040 
    4141def plot_noisy_data(): 
    42     #import sam 
    43     #sam.putarray('st',stations) 
    44     #sam.putarray('data',data) 
    45     #sam.putarray('noise',noise) 
    46     #sam.eval("plot(st(1,:),-data(3,:)+noise(3,:),'k.')") 
    4742    import pylab 
    4843    pylab.plot(stations[0,:],-data[2,:]+noise[2,:],'k.') 
     
    5045def plot_sol(params, linestyle = 'b-'): 
    5146    import pylab 
    52     #import sam 
    5347    s0 = ForwardMogiFactory(params[0:4]) 
    5448    s1 = ForwardMogiFactory(params[4:]) 
     
    5751    ss  = array((xx, yy)) 
    5852    dd = s0(ss) + s1(ss) 
    59     #sam.putarray('ss',ss) 
    60     #sam.putarray('dd',dd) 
    61     #sam.eval("plot(ss(1,:),-dd(3,:),'%s','LineWidth',2)" % linestyle) 
    6253    pylab.plot(ss[0,:],-dd[2,:],'%s'%linestyle,linewidth=2.0) 
    6354 
     
    8879if __name__ == '__main__': 
    8980 
    90     #import sam 
    9181    pylab.ion() 
    9282    plot_noisy_data() 
    93     #sam.eval("hold on") 
    9483    desol, dstepmon = de_solve() 
    9584    print "desol: ", desol 
  • mystic/examples/test_mogi4.py

    r117 r133  
    5757 
    5858    test() 
    59     #import sam 
    6059    import pylab 
    6160    plot_noisy_data() 
    62     #sam.eval("hold on") 
    6361    desol, dstepmon = de_solve(C2) 
    6462    print "desol: ", desol 
  • mystic/examples_other/Make.mm

    r92 r133  
    3434#   test_svr1.py \ 
    3535#   test_svr2.py \ 
     36#   sam_corana.py \ 
     37#   sam_corana2.py \ 
     38#   sam_rosenbrock.py \ 
     39#   sam_cg_rosenbrock.py \ 
     40#   sam_zimmermann.py \ 
     41#   sam_cg_zimmermann.py \ 
     42#   sam_mogi.py \ 
     43#   sam_circle_matlab.py \ 
     44#   qld_circle_dual.py \ 
    3645 
    3746 
  • mystic/mystic/README

    r88 r133  
    33Storn and Price differential evolution solver in python. 
    44 
    5 The parallel framework implementation is being developed in the pyina directory. 
     5The parallel framework implementation is being developed in the pyina branch. 
    66 
    77# end of file 
Note: See TracChangeset for help on using the changeset viewer.