Changeset 82 for tests/sam_mogi.py


Ignore:
Timestamp:
01/26/09 16:12:08 (7 years ago)
Author:
mmckerns
Message:

scipy.optimize.fmin fit to mystic.Solve interface;
mystic handlers, etc added to fmin solver;
VerboseSow? edited to handle simplex-type cloud of results per iteration

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/sam_mogi.py

    r81 r82  
    99import sam 
    1010from test_mogi import * 
    11 from mystic.nelder_mead import fmin 
     11from mystic.scipy_optimize_fmin import NelderMeadSimplexSolver as fmin 
     12from mystic.nmtools import IterationRelativeError as IRE 
    1213from mystic import getch, Sow 
    1314 
     
    6162    z1 = z0*random.uniform(0.5,1.5) 
    6263    v1 = v0*random.uniform(0.5,1.5) 
    63     sol = fmin(cost_function, [random.uniform(x0-40,x0+40), random.uniform(y0-40,y0+40), z1, v1], retall = True, StepMonitor = simplex) 
    64     print sol[0] 
     64    xinit = [random.uniform(x0-40,x0+40), random.uniform(y0-40,y0+40), z1, v1] 
     65 
     66    solver = fmin(len(xinit)) 
     67    solver.SetInitialPoints(xinit) 
     68    killme = IRE(1e-4,1e-4) 
     69    solver.Solve(cost_function, termination=killme, StepMonitor = simplex) 
     70    sol = solver.Solution() 
     71    print sol 
    6572     
    6673    for x in simplex.x: 
    6774        sam.putarray('x',x) 
    6875        sam.eval("plot(x([1,2,3,1],1),x([1,2,3,1],4),'w-','LineWidth',2)") 
    69     return sol[0] 
     76    return sol 
    7077 
    7178 
     
    7481    y1 = y0*random.uniform(0.5,1.5) 
    7582    z1 = z0*random.uniform(0.5,1.5) 
    76     sol = fmin(cost_function, [random.uniform(x0-40,x0+40), y1, z1, random.uniform(v0-0.1,v0+0.1)], retall = True, StepMonitor = simplex) 
    77     print sol[0] 
    78      
     83    xinit = [random.uniform(x0-40,x0+40), y1, z1, random.uniform(v0-0.1,v0+0.1)] 
     84 
     85    solver = fmin(len(xinit)) 
     86    solver.SetInitialPoints(xinit) 
     87    killme = IRE(1e-4,1e-4) 
     88    solver.Solve(cost_function, termination=killme, StepMonitor = simplex) 
     89    sol = solver.Solution() 
     90    print sol 
     91 
    7992    for x in simplex.x: 
    8093        sam.putarray('x',x) 
    8194        sam.eval("plot(x([1,2,3,1],1),x([1,2,3,1],2),'w-','LineWidth',2)") 
    82     return sol[0] 
     95    return sol 
    8396 
    8497draw_contour_xv() 
Note: See TracChangeset for help on using the changeset viewer.