Changeset 82
- Timestamp:
- 01/26/09 16:12:08 (7 years ago)
- Files:
-
- 2 added
- 1 deleted
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
python/Make.mm
r67 r82 31 31 const.py \ 32 32 differential_evolution.py \ 33 nelder_mead.py \ 33 scipy_optimize_fmin.py \ 34 nmtools.py \ 34 35 detools.py \ 35 36 tools.py \ -
python/tools.py
r81 r82 110 110 class Sow(object): 111 111 """ 112 # Instances of objects can be passed as parameters to fmin:112 # Instances of objects can be passed as parameters to solver.Solve(): 113 113 114 114 sow = Sow() 115 fmin(rosen, x0, EvaulationMonitor=sow)115 solver.Solve(rosen, x0, EvaulationMonitor=sow) 116 116 117 117 # Then parameters used to call the CostFunction can be retrieved via -
tests/sam_corana2.py
r81 r82 11 11 import sam 12 12 from test_corana import * 13 from mystic.nelder_mead import fmin, Sow 14 from mystic import getch 13 from mystic.scipy_optimize_fmin import NelderMeadSimplexSolver as fmin 14 from mystic.nmtools import IterationRelativeError as IRE 15 from mystic import getch, Sow 15 16 16 17 def Corana2(x): … … 42 43 def run_once(): 43 44 simplex = Sow() 44 sol = fmin(Corana2, [random.uniform(0,2), random.uniform(0,2)], retall = True, StepMonitor = simplex) 45 solver = fmin(2) 46 solver.SetRandomInitialPoints([0,0],[2,2]) 47 killme = IRE(1e-4,1e-4) 48 solver.Solve(Corana2, termination=killme, StepMonitor = simplex) 49 sol = solver.Solution() 45 50 46 51 for x in simplex.x: -
tests/sam_mogi.py
r81 r82 9 9 import sam 10 10 from test_mogi import * 11 from mystic.nelder_mead import fmin 11 from mystic.scipy_optimize_fmin import NelderMeadSimplexSolver as fmin 12 from mystic.nmtools import IterationRelativeError as IRE 12 13 from mystic import getch, Sow 13 14 … … 61 62 z1 = z0*random.uniform(0.5,1.5) 62 63 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 65 72 66 73 for x in simplex.x: 67 74 sam.putarray('x',x) 68 75 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 70 77 71 78 … … 74 81 y1 = y0*random.uniform(0.5,1.5) 75 82 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 79 92 for x in simplex.x: 80 93 sam.putarray('x',x) 81 94 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 83 96 84 97 draw_contour_xv() -
tests/sam_rosenbrock.py
r81 r82 12 12 import sam 13 13 from test_rosenbrock import * 14 from mystic.nelder_mead import fmin, Sow 15 from mystic import getch 14 from mystic.scipy_optimize_fmin import NelderMeadSimplexSolver as fmin 15 from mystic.nmtools import IterationRelativeError as IRE 16 from mystic import getch, Sow 16 17 17 18 def draw_contour(): … … 40 41 def run_once(x0,x1): 41 42 simplex = Sow() 42 sol = fmin(rosen, [x0, x1], retall = True, StepMonitor = simplex) 43 xinit = [x0, x1] 44 45 solver = fmin(len(xinit)) 46 solver.SetInitialPoints(xinit) 47 killme = IRE(1e-4,1e-4) 48 solver.Solve(rosen, termination=killme, StepMonitor = simplex) 49 sol = solver.Solution() 43 50 44 51 for x in simplex.x: -
tests/sam_zimmermann.py
r81 r82 12 12 import sam 13 13 from test_zimmermann import * 14 from mystic.nelder_mead import fmin 14 from mystic.scipy_optimize_fmin import NelderMeadSimplexSolver as fmin 15 from mystic.nmtools import IterationRelativeError as IRE 15 16 from mystic import getch, Sow 16 17 … … 39 40 def run_once(): 40 41 simplex = Sow() 41 sol = fmin(CostFunction, [random.uniform(0,7), random.uniform(0,7)], retall = True, StepMonitor = simplex) 42 42 solver = fmin(2) 43 solver.SetRandomInitialPoints([0,0],[7,7]) 44 killme = IRE(1e-4,1e-4) 45 solver.Solve(CostFunction, termination=killme, StepMonitor = simplex) 46 sol = solver.Solution() 47 43 48 for x in simplex.x: 44 49 sam.putarray('x',x) -
tests/test_dejong3.py
r62 r82 63 63 print "CPU Time: %s" % timetaken 64 64 65 from mystic. nelder_mead import fmin65 from mystic.scipy_optimize_fmin import fmin 66 66 67 67 print fmin(DeJong3, [0 for i in range(5)]) -
tests/test_mogi.py
r81 r82 110 110 if __name__ == '__main__': 111 111 112 from mystic.nelder_mead import fmin 112 from mystic.scipy_optimize_fmin import NelderMeadSimplexSolver as fmin 113 from mystic.nmtools import IterationRelativeError as IRE 113 114 from scipy.optimize import leastsq, fmin_cg 114 115 # … … 125 126 # 126 127 simplex, esow = Sow(), Sow() 127 sol = fmin(cost_function, point, EvaluationMonitor = esow, retall = True, StepMonitor = simplex) 128 print "simplex solution: ", sol[1][-1] 128 solver = fmin(len(point)) 129 solver.SetInitialPoints(point) 130 killme = IRE(1e-4,1e-4) 131 solver.Solve(cost_function, killme, EvaluationMonitor = esow, StepMonitor = simplex) 132 sol = solver.Solution() 133 134 print "simplex solution: ", sol 129 135 # 130 136 solcg = fmin_cg(cost_function, point) … … 137 143 plot_noisy_data() 138 144 plot_sol(desol,'r-') 139 plot_sol(sol [1][-1],'k--')145 plot_sol(sol,'k--') 140 146 plot_sol(solcg,'b-.') 141 147 pylab.legend(('Noisy data', 'Differential Evolution', 'Nelder Mead', 'Polak Ribiere')) -
tests/test_rosenbrock.py
r5 r82 13 13 from mystic.differential_evolution import DifferentialEvolutionSolver 14 14 from mystic.detools import Best1Exp, Rand1Exp, Best2Bin, ChangeOverGeneration, VTR 15 from mystic.nelder_mead import fmin, rosen 15 from mystic.scipy_optimize_fmin import __rosen as rosen 16 from mystic.scipy_optimize_fmin import NelderMeadSimplexSolver as fmin 17 from mystic.nmtools import IterationRelativeError as IRE 16 18 from mystic import Sow 17 19 … … 45 47 esow= Sow() 46 48 ssow= Sow() 47 sol = fmin(rosen, [random.random() for j in range(ND)], full_output=1, retall=1, EvaluationMonitor=esow, SimplexMonitor=ssow) 48 print sol[0] 49 xinit = [random.random() for j in range(ND)] 50 51 solver = fmin(len(xinit)) 52 solver.SetInitialPoints(xinit) 53 killme = IRE(1e-4,1e-4) 54 solver.Solve(rosen, killme, EvaluationMonitor = esow, StepMonitor = ssow) 55 sol = solver.Solution() 56 print sol 49 57 50 58 print len(esow.x) -
tests/test_zimmermann.py
r81 r82 63 63 64 64 from mystic import Sow 65 from mystic.nelder_mead import fmin 65 from mystic.scipy_optimize_fmin import NelderMeadSimplexSolver as fmin 66 from mystic.nmtools import IterationRelativeError as IRE 66 67 67 68 simplex = Sow() 68 69 esow = Sow() 69 sol = fmin(CostFunction, [random.uniform(0,5) for j in range(ND)], EvaluationMonitor = esow, retall = True, StepMonitor = simplex) 70 #print "solution: ", sol 70 xinit = [random.uniform(0,5) for j in range(ND)] 71 72 solver = fmin(len(xinit)) 73 solver.SetInitialPoints(xinit) 74 killme = IRE(1e-4,1e-4) 75 solver.Solve(CostFunction, killme, EvaluationMonitor = esow, StepMonitor = simplex) 76 sol = solver.Solution() 77 print "solution: ", sol 71 78 72 79 # end of file
Note: See TracChangeset
for help on using the changeset viewer.