Changeset 466
- Timestamp:
- 07/02/11 20:41:02 (5 years ago)
- Location:
- mystic
- Files:
-
- 1 added
- 49 edited
Legend:
- Unmodified
- Added
- Removed
-
mystic/_math/measures.py
r465 r466 238 238 from mystic.termination import VTR 239 239 from mystic.strategy import Best1Exp 240 from mystic.tools import random_seed, VerboseSow, Sow 240 from mystic.monitors import VerboseMonitor, Monitor 241 from mystic.tools import random_seed 241 242 if debug: random_seed(123) 242 evalmon = Sow(); stepmon = Sow()243 if debug: stepmon = Verbose Sow(10)243 evalmon = Monitor(); stepmon = Monitor() 244 if debug: stepmon = VerboseMonitor(10) 244 245 245 246 ndim = len(lb) -
mystic/examples/NOTES
r133 r466 115 115 - MAX_GENERATIONS is maximum optimization iterations 116 116 #----------------------------------------------------------------------------- 117 - Verbose Sowlogs/prints "goodness of fit" and "best solution" at each step117 - VerboseMonitor logs/prints "goodness of fit" and "best solution" at each step 118 118 - minrange/maxrange provide box constraints (for parameters a,b,c) 119 119 - SetRandomInitialPoints chooses an initial solution within box constraints … … 127 127 solver.enable_signal_handler() 128 128 129 stepmon = Verbose Sow(10,50)129 stepmon = VerboseMonitor(10,50) 130 130 minrange = [-100., -100., -100.]; maxrange = [100., 100., 100.]; 131 131 solver.SetRandomInitialPoints(min = minrange, max = maxrange) -
mystic/examples/TEST_ffitPP.py
r465 r466 29 29 solver.Solve(ChebyshevCost, termination=VTR(0.01), strategy=strategy, \ 30 30 CrossProbability=1.0, ScalingFactor=0.9 , \ 31 StepMonitor=Verbose Sow(30), sigint_callback=plot_solution)31 StepMonitor=VerboseMonitor(30), sigint_callback=plot_solution) 32 32 33 33 solution = solver.Solution() -
mystic/examples/TEST_ffitPP_b.py
r465 r466 57 57 solver.Solve(ChebyshevCost, termination=VTR(0.01), strategy=strategy, \ 58 58 CrossProbability=1.0, ScalingFactor=0.9 , \ 59 StepMonitor=Verbose Sow(30), sigint_callback=plot_solution)59 StepMonitor=VerboseMonitor(30), sigint_callback=plot_solution) 60 60 61 61 solution = solver.Solution() -
mystic/examples/buckshot_example06.py
r465 r466 24 24 from mystic.termination import NormalizedChangeOverGeneration as NCOG 25 25 from mystic.math import poly1d 26 from mystic.tools import getch, VerboseSow 26 from mystic.monitors import VerboseMonitor 27 from mystic.tools import getch 27 28 import pylab 28 29 pylab.ion() … … 68 69 69 70 # configure monitor 70 stepmon = Verbose Sow(1)71 stepmon = VerboseMonitor(1) 71 72 72 73 # use buckshot-Powell to solve 8th-order Chebyshev coefficients -
mystic/examples/example08.py
r465 r466 25 25 from mystic.termination import VTR 26 26 from mystic.strategy import Best1Exp 27 from mystic.tools import getch, random_seed, VerboseSow 27 from mystic.monitors import VerboseMonitor 28 from mystic.tools import getch, random_seed 28 29 from mystic.math import poly1d 29 30 import pylab … … 69 70 70 71 # configure monitor 71 stepmon = Verbose Sow(50)72 stepmon = VerboseMonitor(50) 72 73 73 74 # use DE to solve 8th-order Chebyshev coefficients -
mystic/examples/example09.py
r465 r466 27 27 from mystic.termination import VTR 28 28 from mystic.strategy import Best1Exp 29 from mystic.tools import getch, random_seed, VerboseSow 29 from mystic.monitors import VerboseMonitor 30 from mystic.tools import getch, random_seed 30 31 from mystic.math import poly1d 31 32 import pylab … … 75 76 76 77 # configure monitor 77 stepmon = Verbose Sow(50)78 stepmon = VerboseMonitor(50) 78 79 79 80 # use DE to solve 8th-order Chebyshev coefficients -
mystic/examples/example10.py
r465 r466 25 25 from mystic.termination import VTR 26 26 from mystic.strategy import Best1Exp 27 from mystic.tools import getch, random_seed, VerboseSow, Sow 27 from mystic.monitors import VerboseMonitor, Monitor 28 from mystic.tools import getch, random_seed 28 29 from mystic.math import poly1d 29 30 import pylab … … 57 58 58 59 # configure monitors 59 stepmon = Verbose Sow(50)60 evalmon = Sow()60 stepmon = VerboseMonitor(50) 61 evalmon = Monitor() 61 62 62 63 # use DE to solve 8th-order Chebyshev coefficients -
mystic/examples/example11.py
r465 r466 25 25 # tools 26 26 from mystic.termination import CandidateRelativeTolerance as CRT 27 from mystic.tools import getch, random_seed, VerboseSow, Sow 27 from mystic.monitors import VerboseMonitor, Monitor 28 from mystic.tools import getch, random_seed 28 29 from mystic.math import poly1d 29 30 import pylab … … 94 95 95 96 # configure monitors 96 stepmon = Verbose Sow(100)97 evalmon = Sow()97 stepmon = VerboseMonitor(100) 98 evalmon = Monitor() 98 99 99 100 # use Nelder-Mead to solve 8th-order Chebyshev coefficients -
mystic/examples/ezmap_desolve.py
r465 r466 29 29 from mystic.termination import ChangeOverGeneration, VTR 30 30 from mystic.strategy import Best1Exp 31 from mystic.tools import VerboseSow, random_seed 31 from mystic.monitors import VerboseMonitor 32 from mystic.tools import random_seed 32 33 from mystic.math import poly1d 33 34 … … 49 50 return 50 51 51 psow = Verbose Sow(10)52 ssow = Verbose Sow(10)52 psow = VerboseMonitor(10) 53 ssow = VerboseMonitor(10) 53 54 54 55 random_seed(seed) -
mystic/examples/ezmap_desolve_rosen.py
r465 r466 30 30 from mystic.termination import ChangeOverGeneration, VTR 31 31 from mystic.strategy import Best1Exp 32 from mystic.tools import VerboseSow, random_seed 32 from mystic.monitors import VerboseMonitor 33 from mystic.tools import random_seed 33 34 34 35 #from raw_rosen import rosen as myCost # ez_map needs a helper function … … 53 54 return 54 55 55 psow = Verbose Sow(10)56 ssow = Verbose Sow(10)56 psow = VerboseMonitor(10) 57 ssow = VerboseMonitor(10) 57 58 58 59 random_seed(seed) -
mystic/examples/lattice_example06.py
r465 r466 24 24 from mystic.termination import NormalizedChangeOverGeneration as NCOG 25 25 from mystic.math import poly1d 26 from mystic.tools import getch, VerboseSow 26 from mystic.monitors import VerboseMonitor 27 from mystic.tools import getch 27 28 import pylab 28 29 pylab.ion() … … 69 70 70 71 # configure monitor 71 stepmon = Verbose Sow(1)72 stepmon = VerboseMonitor(1) 72 73 73 74 # use lattice-Powell to solve 8th-order Chebyshev coefficients -
mystic/examples/rosetta_mogi.py
r465 r466 70 70 # --- Call to Mystic's Fmin optimizer --- 71 71 def mystic_optimize(point): 72 from mystic.tools import getch, Sow, random_seed, VerboseSow 72 from mystic.monitors import Monitor, VerboseMonitor 73 from mystic.tools import getch, random_seed 73 74 random_seed(123) 74 75 from mystic.solvers import NelderMeadSimplexSolver as fmin 75 76 from mystic.termination import CandidateRelativeTolerance as CRT 76 simplex, esow = Verbose Sow(50), Sow()77 simplex, esow = VerboseMonitor(50), Monitor() 77 78 solver = fmin(len(point)) 78 79 solver.SetInitialPoints(point) … … 84 85 # --- Call to Mystic's DE optimizer --- 85 86 def mystic_optimize2(point): 86 from mystic.tools import getch, Sow, random_seed, VerboseSow 87 from mystic.monitors import Monitor, VerboseMonitor 88 from mystic.tools import getch, random_seed 87 89 random_seed(123) 88 90 from mystic.solvers import DifferentialEvolutionSolver as de 89 91 from mystic.termination import ChangeOverGeneration as COG 90 92 NPOP = 50 91 simplex, esow = Verbose Sow(50), Sow()93 simplex, esow = VerboseMonitor(50), Monitor() 92 94 solver = de(len(point),NPOP) 93 95 solver.SetInitialPoints(point) -
mystic/examples/rosetta_parabola.py
r465 r466 52 52 # --- Call to Mystic --- 53 53 def mystic_optimize(point): 54 from mystic. tools import Sow, VerboseSow54 from mystic.monitors import Monitor, VerboseMonitor 55 55 from mystic.solvers import NelderMeadSimplexSolver as fmin 56 56 from mystic.termination import CandidateRelativeTolerance as CRT 57 simplex, esow = Verbose Sow(50), Sow()57 simplex, esow = VerboseMonitor(50), Monitor() 58 58 solver = fmin(len(point)) 59 59 solver.SetInitialPoints(point) -
mystic/examples/test_br8.py
r465 r466 13 13 from mystic.termination import ChangeOverGeneration, VTR 14 14 from mystic.tools import getch, random_seed 15 from mystic. tools import VerboseSow as MySow15 from mystic.monitors import VerboseMonitor as MyMonitor 16 16 17 17 from mystic.models.br8 import decay; F = decay.ForwardFactory … … 63 63 solver = DifferentialEvolutionSolver(ND, NP) 64 64 solver.enable_signal_handler() 65 stepmon = My Sow(interval)65 stepmon = MyMonitor(interval) 66 66 solver.SetRandomInitialPoints(min=minrange,max=maxrange) 67 67 solver.SetStrictRanges(min=minrange, max=maxrange) -
mystic/examples/test_ffit.py
r465 r466 19 19 from mystic.strategy import Best1Exp, Best1Bin, Rand1Exp 20 20 from mystic.math import poly1d 21 from mystic.tools import getch, VerboseSow 21 from mystic.monitors import VerboseMonitor 22 from mystic.tools import getch 22 23 23 24 import random … … 72 73 solver.Solve(ChebyshevCost, termination=VTR(0.01), strategy=strategy, \ 73 74 CrossProbability=1.0, ScalingFactor=0.9 , \ 74 StepMonitor=Verbose Sow(30), sigint_callback=plot_solution)75 StepMonitor=VerboseMonitor(30), sigint_callback=plot_solution) 75 76 76 77 solution = solver.Solution() -
mystic/examples/test_ffit2.py
r465 r466 15 15 from mystic.strategy import Best1Exp, Best1Bin, Rand1Exp, Best2Bin, Best2Exp 16 16 from mystic.math import poly1d 17 from mystic. tools import VerboseSow17 from mystic.monitors import VerboseMonitor 18 18 from mystic.models.poly import chebyshev16cost 19 19 … … 49 49 50 50 solver.Solve(ChebyshevCost, termination=VTR(0.0001), strategy=strategy, \ 51 StepMonitor=Verbose Sow(10), CrossProbability=1.0, ScalingFactor=0.6)51 StepMonitor=VerboseMonitor(10), CrossProbability=1.0, ScalingFactor=0.6) 52 52 53 53 solution = solver.Solution() -
mystic/examples/test_ffitB.py
r465 r466 27 27 solver.Solve(ChebyshevCost, termination=VTR(0.01), strategy=strategy, \ 28 28 CrossProbability=1.0, ScalingFactor=0.9 , \ 29 StepMonitor=Verbose Sow(30), sigint_callback=plot_solution)29 StepMonitor=VerboseMonitor(30), sigint_callback=plot_solution) 30 30 31 31 solution = solver.Solution() -
mystic/examples/test_getCost.py
r465 r466 12 12 from mystic.models import poly; PolyCostFactory = poly.CostFactory 13 13 from mystic.solvers import DifferentialEvolutionSolver 14 from mystic.tools import VerboseSow, getch 14 from mystic.monitors import VerboseMonitor 15 from mystic.tools import getch 15 16 16 17 ND = 3 … … 29 30 solver.enable_signal_handler() 30 31 31 stepmon = Verbose Sow(10,50)32 stepmon = VerboseMonitor(10,50) 32 33 minrange = [-100., -100., -100.]; 33 34 maxrange = [100., 100., 100.]; -
mystic/examples/test_lorentzian.py
r117 r466 52 52 solver = DifferentialEvolutionSolver(ND, NP) 53 53 solver.enable_signal_handler() 54 stepmon = Sow()54 stepmon = Monitor() 55 55 solver.SetRandomInitialPoints(min=minrange,max=maxrange) 56 56 solver.SetStrictRanges(min=minrange,max=maxrange) -
mystic/examples/test_lorentzian2.py
r465 r466 13 13 from mystic.termination import ChangeOverGeneration, VTR 14 14 from mystic.strategy import Best1Exp, Rand1Exp, Best2Exp, Best2Exp 15 from mystic.tools import getch, Sow, random_seed 15 from mystic.monitors import Monitor 16 from mystic.tools import getch, random_seed 16 17 17 18 random.seed(123) … … 53 54 solver = DifferentialEvolutionSolver(ND, NP) 54 55 solver.enable_signal_handler() 55 stepmon = Sow()56 stepmon = Monitor() 56 57 solver.SetRandomInitialPoints(min=minrange,max=maxrange) 57 58 solver.SetStrictRanges(min=minrange,max=maxrange) -
mystic/examples/test_mogi.py
r465 r466 23 23 from mystic.solvers import DifferentialEvolutionSolver 24 24 from mystic.termination import ChangeOverGeneration, VTR 25 from mystic.tools import getch, Sow, random_seed, VerboseSow 25 from mystic.monitors import Monitor, VerboseMonitor 26 from mystic.tools import getch, random_seed 26 27 27 28 from numpy import pi, sqrt, array, mgrid, random, real, conjugate, arange … … 82 83 solver = DifferentialEvolutionSolver(ND, NP) 83 84 84 stepmon = Sow()85 stepmon = Monitor() 85 86 minrange = [-1000., -1000., -100., -10.]; 86 87 maxrange = [1000., 1000., 100., 10.]; … … 124 125 #point = dstepmon.x[-150] 125 126 # 126 simplex, esow = Sow(), Sow()127 simplex, esow = Monitor(), Monitor() 127 128 solver = fmin(len(point)) 128 129 solver.SetInitialPoints(point) -
mystic/examples/test_mogi2.py
r133 r466 62 62 solver.enable_signal_handler() 63 63 64 stepmon = Verbose Sow()64 stepmon = VerboseMonitor() 65 65 minrange = [-1000., -1000., -100., -1.]*2; 66 66 maxrange = [1000., 1000., 100., 1.]*2; -
mystic/examples/test_mogi3.py
r117 r466 15 15 solver = DifferentialEvolutionSolver(ND, NP) 16 16 17 stepmon = Sow()17 stepmon = Monitor() 18 18 minrange = [-1000., -1000., -100., -10.]; 19 19 maxrange = [1000., 1000., 100., 10.]; -
mystic/examples/test_mogi4.py
r465 r466 8 8 from mystic.solvers import DifferentialEvolutionSolver 9 9 from mystic.termination import ChangeOverGeneration, VTR 10 from mystic.tools import getch, Sow, random_seed 10 from mystic.monitors import Monitor 11 from mystic.tools import getch, random_seed 11 12 12 13 from mystic.forward_model import CostFactory … … 18 19 solver.enable_signal_handler() 19 20 20 stepmon = Sow()21 stepmon = Monitor() 21 22 minrange = [-1000., -1000., -100., -1.]*2; 22 23 maxrange = [1000., 1000., 100., 1.]*2; -
mystic/examples/test_rosenbrock.py
r465 r466 16 16 from mystic.termination import ChangeOverGeneration, VTR 17 17 from mystic.models import rosen 18 from mystic. tools import Sow, VerboseSow18 from mystic.monitors import Monitor, VerboseMonitor 19 19 20 20 import random … … 62 62 print "======================" 63 63 start = time.time() 64 esow= Sow()65 ssow= Sow()66 #ssow= Verbose Sow(1)64 esow= Monitor() 65 ssow= Monitor() 66 #ssow= VerboseMonitor(1) 67 67 68 68 # xinit = [random.random() for j in range(ND)] -
mystic/examples/test_rosenbrock2.py
r465 r466 24 24 print "===================" 25 25 start = time.time() 26 from mystic. tools import Sow, VerboseSow27 #stepmon = Verbose Sow(1)28 stepmon = Sow() #VerboseSow(10)26 from mystic.monitors import Monitor, VerboseMonitor 27 #stepmon = VerboseMonitor(1) 28 stepmon = Monitor() #VerboseMonitor(10) 29 29 from mystic.termination import CandidateRelativeTolerance as CRT 30 30 -
mystic/examples/test_rosenbrock3.py
r465 r466 28 28 print "===========================" 29 29 start = time.time() 30 from mystic. tools import Sow, VerboseSow31 stepmon = Verbose Sow(1,1)32 #stepmon = Sow() #VerboseSow(10)30 from mystic.monitors import Monitor, VerboseMonitor 31 stepmon = VerboseMonitor(1,1) 32 #stepmon = Monitor() #VerboseMonitor(10) 33 33 from mystic.termination import NormalizedChangeOverGeneration as NCOG 34 34 -
mystic/examples/test_wavy.py
r465 r466 8 8 from mystic.termination import ChangeOverGeneration, VTR 9 9 from mystic.strategy import Best1Exp, Best1Bin, Rand1Exp 10 from mystic.tools import getch, VerboseSow 10 from mystic.monitors import VerboseMonitor 11 from mystic.tools import getch 11 12 from numpy import arange 12 13 from mystic.solvers import fmin … … 52 53 53 54 strategy = Best1Bin 54 stepmon = Verbose Sow(1)55 stepmon = VerboseMonitor(1) 55 56 solver.Solve(wavy, 56 57 termination = ChangeOverGeneration(generations=50), \ -
mystic/examples/test_zimmermann.py
r465 r466 51 51 print "CPU Time: %s" % timetaken 52 52 53 from mystic. tools import Sow53 from mystic.monitors import Monitor 54 54 from mystic.solvers import NelderMeadSimplexSolver as fmin 55 55 from mystic.termination import CandidateRelativeTolerance as CRT 56 56 57 simplex = Sow()58 esow = Sow()57 simplex = Monitor() 58 esow = Monitor() 59 59 xinit = [random.uniform(0,5) for j in range(ND)] 60 60 -
mystic/examples_other/sam_corana2.py
r465 r466 13 13 from mystic.solvers import NelderMeadSimplexSolver as fmin 14 14 from mystic.termination import CandidateRelativeTolerance as CRT 15 from mystic.tools import getch, Sow 15 from mystic.monitors import Monitor 16 from mystic.tools import getch 16 17 17 18 from mystic.models.corana import corana2d as Corana2 … … 41 42 42 43 def run_once(): 43 simplex = Sow()44 simplex = Monitor() 44 45 solver = fmin(2) 45 46 solver.SetRandomInitialPoints([0,0],[2,2]) -
mystic/examples_other/sam_mogi.py
r465 r466 11 11 from mystic.solvers import NelderMeadSimplexSolver as fmin 12 12 from mystic.termination import CandidateRelativeTolerance as CRT 13 from mystic.tools import getch, Sow 13 from mystic.monitors import Monitor 14 from mystic.tools import getch 14 15 15 16 x0,y0,z0,v0 = actual_params … … 59 60 60 61 def run_once_xy(): 61 simplex = Sow()62 simplex = Monitor() 62 63 z1 = z0*random.uniform(0.5,1.5) 63 64 v1 = v0*random.uniform(0.5,1.5) … … 77 78 78 79 def run_once_xv(): 79 simplex = Sow()80 simplex = Monitor() 80 81 y1 = y0*random.uniform(0.5,1.5) 81 82 z1 = z0*random.uniform(0.5,1.5) -
mystic/examples_other/sam_rosenbrock.py
r465 r466 14 14 from mystic.solvers import NelderMeadSimplexSolver as fmin 15 15 from mystic.termination import CandidateRelativeTolerance as CRT 16 from mystic.tools import getch, Sow 16 from mystic.monitors import Monitor 17 from mystic.tools import getch 17 18 18 19 def draw_contour(): … … 40 41 41 42 def run_once(x0,x1): 42 simplex = Sow()43 simplex = Monitor() 43 44 xinit = [x0, x1] 44 45 -
mystic/examples_other/sam_zimmermann.py
r465 r466 14 14 from mystic.solvers import NelderMeadSimplexSolver as fmin 15 15 from mystic.termination import CandidateRelativeTolerance as CRT 16 from mystic.tools import getch, Sow 16 from mystic.monitors import Monitor 17 from mystic.tools import getch 17 18 18 19 def draw_contour(): … … 39 40 40 41 def run_once(): 41 simplex = Sow()42 simplex = Monitor() 42 43 solver = fmin(2) 43 44 solver.SetRandomInitialPoints([0,0],[7,7]) -
mystic/mystic/Make.mm
r465 r466 38 38 helputil.py \ 39 39 linesearch.py \ 40 monitors.py \ 40 41 mystic_math.py \ 41 42 nested.py \ -
mystic/mystic/__init__.py
r465 r466 153 153 - mystic.mystic.termination [solver termination conditions] 154 154 - mystic.mystic.strategy [solver population mutation strategies] 155 - mystic.mystic.tools [monitors, function wrappers, and other tools] 155 - mystic.mystic.monitors [optimization monitors] 156 - mystic.mystic.tools [function wrappers, etc] 156 157 - mystic.mystic.forward_model [cost function generator] 157 158 - mystic.models [a collection of standard models] … … 237 238 238 239 # monitors, function wrappers, and other tools 239 #import monitors240 import monitors 240 241 import munge 241 242 import tools -
mystic/mystic/_genSow.py
r335 r466 3 3 # Mike McKerns, Caltech 4 4 5 """a helper class for the Custom Sowfunction"""5 """a helper class for the CustomMonitor function""" 6 6 7 7 class genSow(object): 8 8 """ 9 a configurable Sow (monitor)generator9 a configurable Monitor generator 10 10 """ 11 11 def __init__(self,**kwds): 12 12 """ 13 Build a Sow, with channels for the provided properties13 Build a Monitor, with channels for the provided properties 14 14 Takes **kwds of the form property="doc". 15 15 """ … … 32 32 """ 33 33 Takes string names of properties (given as *args), and sets the 34 corresponding properties as required inputs for the Sow.34 corresponding properties as required inputs for the Monitor. 35 35 """ 36 36 self.__args = [ i for i in args if self.__dict.has_key(i) ] 37 exec(self._genClass()) # generates Sow()38 return Sow()37 exec(self._genClass()) # generates Monitor() 38 return Monitor() 39 39 #return self._genClass() 40 40 41 41 def _genClass(self): 42 """append the code blocks for the entire Sowclass"""42 """append the code blocks for the entire Monitor class""" 43 43 code = self.__genHead() + \ 44 44 self.__genInit() + \ … … 49 49 50 50 def __genHead(self): 51 """build the code block for the Sowclass header"""51 """build the code block for the Monitor class header""" 52 52 code0 = """ 53 class Sow(object):53 class Monitor(object): 54 54 """ 55 55 return code0 56 56 57 57 def __genInit(self): 58 """build the code block for the Sowclass __init__ method"""58 """build the code block for the Monitor class __init__ method""" 59 59 code1 = """ 60 60 def __init__(self): … … 65 65 66 66 def __genCall(self): 67 """build the code block for the Sowclass __call__ method"""67 """build the code block for the Monitor class __call__ method""" 68 68 code2 = """ 69 69 def __call__(self,""" … … 81 81 82 82 def __genMeth(self): 83 """build the code block for the remaining Sowclass methods"""83 """build the code block for the remaining Monitor class methods""" 84 84 code3 = """ 85 85 """ … … 89 89 90 90 def __genProp(self): 91 """build the code block for the Sowclass properties"""91 """build the code block for the Monitor class properties""" 92 92 code4 = """ 93 93 """ -
mystic/mystic/abstract_map_solver.py
r462 r466 31 31 >>> 32 32 >>> # get monitors and termination condition objects 33 >>> from mystic. tools import Sow34 >>> stepmon = Sow()33 >>> from mystic.monitors import Monitor 34 >>> stepmon = Monitor() 35 35 >>> from mystic.termination import CandidateRelativeTolerance as CRT 36 36 >>> … … 43 43 >>> 44 44 >>> # instantiate and configure the solver 45 >>> from mystic. nestedimport ScattershotSolver45 >>> from mystic.solvers import ScattershotSolver 46 46 >>> solver = ScattershotSolver(len(lb), npts) 47 47 >>> solver.SetMapper(ez_map2, equalportion_mapper) -
mystic/mystic/abstract_nested_solver.py
r462 r466 31 31 >>> 32 32 >>> # get monitors and termination condition objects 33 >>> from mystic. tools import Sow34 >>> stepmon = Sow()33 >>> from mystic.monitors import Monitor 34 >>> stepmon = Monitor() 35 35 >>> from mystic.termination import CandidateRelativeTolerance as CRT 36 36 >>> … … 42 42 >>> 43 43 >>> # instantiate and configure the solver 44 >>> from mystic.s cipy_optimizeimport NelderMeadSimplexSolver45 >>> from mystic. nestedimport BatchGridSolver44 >>> from mystic.solvers import NelderMeadSimplexSolver 45 >>> from mystic.solvers import BatchGridSolver 46 46 >>> solver = BatchGridSolver(len(nbins), nbins) 47 47 >>> solver.SetNestedSolver(NelderMeadSimplexSolver) … … 118 118 if kwds.has_key('npts'): npts = kwds['npts'] 119 119 self._npts = npts 120 from mystic.s cipy_optimizeimport NelderMeadSimplexSolver120 from mystic.solvers import NelderMeadSimplexSolver 121 121 self._solver = NelderMeadSimplexSolver 122 122 return -
mystic/mystic/abstract_solver.py
r462 r466 24 24 >>> 25 25 >>> # get monitors and termination condition objects 26 >>> from mystic. tools import Sow27 >>> stepmon = Sow()28 >>> evalmon = Sow()26 >>> from mystic.monitors import Monitor 27 >>> stepmon = Monitor() 28 >>> evalmon = Monitor() 29 29 >>> from mystic.termination import CandidateRelativeTolerance as CRT 30 30 >>> 31 31 >>> # instantiate and configure the solver 32 >>> from mystic.s cipy_optimizeimport NelderMeadSimplexSolver32 >>> from mystic.solvers import NelderMeadSimplexSolver 33 33 >>> solver = NelderMeadSimplexSolver(len(x0)) 34 34 >>> solver.SetInitialPoints(x0) … … 48 48 >>> 49 49 >>> # configure the solver and obtain the solution 50 >>> from mystic.s cipy_optimizeimport fmin50 >>> from mystic.solvers import fmin 51 51 >>> solution = fmin(rosen,x0) 52 52 -
mystic/mystic/constraints.py
r440 r466 546 546 return 1. 547 547 548 from mystic. differential_evolutionimport DifferentialEvolutionSolver548 from mystic.solvers import DifferentialEvolutionSolver 549 549 from mystic.termination import ChangeOverGeneration as COG 550 550 solver = DifferentialEvolutionSolver(ndim, 40) -
mystic/mystic/differential_evolution.py
r465 r466 50 50 51 51 Mystic solver behavior activated in diffev and diffev2:: 52 - EvaluationMonitor = Sow()53 - StepMonitor = Sow()52 - EvaluationMonitor = Monitor() 53 - StepMonitor = Monitor() 54 54 - enable_signal_handler() 55 55 - strategy = Best1Exp … … 671 671 invariant_current = kwds['invariant_current'] 672 672 673 from mystic. tools import Sow674 stepmon = Sow()675 evalmon = Sow()673 from mystic.monitors import Monitor 674 stepmon = Monitor() 675 evalmon = Monitor() 676 676 #from mystic.strategy import Best1Exp #, Best1Bin, Rand1Exp 677 677 #strategy = Best1Exp -
mystic/mystic/nested.py
r465 r466 134 134 def local_optimize(cost, termination, x0, rank): 135 135 from %s import %s as LocalSolver 136 from mystic. tools import Sow137 138 stepmon = Sow()139 evalmon = Sow()136 from mystic.monitors import Monitor 137 138 stepmon = Monitor() 139 evalmon = Monitor() 140 140 141 141 ndim = len(x0) … … 308 308 def local_optimize(cost, termination, x0, rank): 309 309 from %s import %s as LocalSolver 310 from mystic. tools import Sow311 312 stepmon = Sow()313 evalmon = Sow()310 from mystic.monitors import Monitor 311 312 stepmon = Monitor() 313 evalmon = Monitor() 314 314 315 315 ndim = len(x0) -
mystic/mystic/scipy_optimize.py
r462 r466 32 32 33 33 Mystic solver behavior activated in fmin:: 34 - EvaluationMonitor = Sow()35 - StepMonitor = Sow()34 - EvaluationMonitor = Monitor() 35 - StepMonitor = Monitor() 36 36 - termination = CandidateRelativeTolerance(xtol,ftol) 37 37 - enable_signal_handler() 38 38 39 39 Mystic solver behavior activated in fmin_powell:: 40 - EvaluationMonitor = Sow()41 - StepMonitor = Sow()40 - EvaluationMonitor = Monitor() 41 - StepMonitor = Monitor() 42 42 - termination = NormalizedChangeOverGeneration(ftol) 43 43 - enable_signal_handler() … … 390 390 """ 391 391 392 from mystic. tools import Sow393 stepmon = Sow()394 evalmon = Sow()392 from mystic.monitors import Monitor 393 stepmon = Monitor() 394 evalmon = Monitor() 395 395 from mystic.termination import CandidateRelativeTolerance as CRT 396 396 … … 702 702 # - should just pass 'direc', and then hands-off ? How return it ? 703 703 704 from mystic. tools import Sow705 stepmon = Sow()706 evalmon = Sow()704 from mystic.monitors import Monitor 705 stepmon = Monitor() 706 evalmon = Monitor() 707 707 from mystic.termination import NormalizedChangeOverGeneration as NCOG 708 708 -
mystic/mystic/tools.py
r430 r466 17 17 - Null: a Null object pattern 18 18 - getch: provides "press any key to quit" 19 - Sow: A class whose instances are callable (to be used as monitors)20 - VerboseSow: A verbose version of the basic Sow21 - LoggingSow: A version of the basic Sow that logs to a file22 - CustomSow: A customizable 'n-variable' version of the basic Sow23 19 - random_seed: sets the seed for calls to 'random()' 24 20 - wrap_nested: nest a function call within a function object … … 119 115 print str + " and press enter" 120 116 return raw_input() 121 122 class Sow(object):123 """124 Instances of objects that can be passed as monitors.125 The Sow logs the parameters and corresponding costs,126 retrievable by accessing the Sow's member variables.127 128 example usage...129 >>> sow = Sow()130 >>> solver.Solve(rosen, x0, EvaulationMonitor=sow)131 >>> sow.x # get log of parameters132 >>> sow.y # get log of costs133 134 """135 def __init__(self, **kwds):#, all=True):136 self._x = []137 self._y = []138 self._id = []139 #self._all = all140 141 def __call__(self, x, y, id=None, **kwds):#, best=0):142 self._x.append(listify(x)) #XXX: better to save as-is?143 self._y.append(listify(y)) #XXX: better to save as-is?144 self._id.append(id)145 #if not self._all and list_or_tuple_or_ndarray(x):146 # self._x[-1] = self._x[-1][best]147 #if not self._all and list_or_tuple_or_ndarray(y):148 # self._y[-1] = self._y[-1][best]149 150 def get_x(self):151 return self._x152 153 def get_y(self):154 return self._y155 156 def get_id(self):157 return self._id158 159 x = property(get_x, doc = "Params")160 y = property(get_y, doc = "Costs")161 id = property(get_id, doc = "Id")162 pass163 164 class VerboseSow(Sow):165 """A verbose version of the basic Sow.166 167 Prints ChiSq every 'interval', and optionally prints168 current parameters every 'xinterval'.169 """170 import numpy171 def __init__(self, interval = 10, xinterval = numpy.inf, all=True):172 super(VerboseSow,self).__init__()173 self._step = 0174 self._yinterval = interval175 self._xinterval = xinterval176 self._all = all177 return178 def __call__(self, x, y, id=None, best=0):179 super(VerboseSow,self).__call__(x, y, id)180 if int(self._step % self._yinterval) == 0:181 if not list_or_tuple_or_ndarray(y):182 who = ''183 y = " %f" % self._y[-1]184 elif self._all:185 who = ''186 y = " %s" % self._y[-1]187 else:188 who = ' best'189 y = " %f" % self._y[-1][best]190 msg = "Generation %d has%s Chi-Squared:%s" % (self._step, who, y)191 if id != None: msg = "[id: %d] " % (id) + msg192 print msg193 if int(self._step % self._xinterval) == 0:194 if not list_or_tuple_or_ndarray(x):195 who = ''196 x = " %f" % self._x[-1]197 elif self._all:198 who = ''199 x = "\n %s" % self._x[-1]200 else:201 who = ' best'202 x = "\n %s" % self._x[-1][best]203 msg = "Generation %d has%s fit parameters:%s" % (self._step, who, x)204 if id != None: msg = "[id: %d] " % (id) + msg205 print msg206 self._step += 1207 return208 pass209 210 class LoggingSow(Sow):211 """A version of the basic Sow that writes to a file at specified intervals.212 213 Logs ChiSq and parameters to a file every 'interval'214 """215 import numpy216 def __init__(self, interval=1, filename='log.txt', new=False, all=True):217 import datetime218 super(LoggingSow,self).__init__()219 self._filename = filename220 self._step = 0221 self._yinterval = interval222 self._xinterval = interval223 if new: ind = 'w'224 else: ind = 'a'225 self._file = open(self._filename,ind)226 self._file.write("# %s\n" % datetime.datetime.now().ctime() )227 self._file.write("# ___#___ __ChiSq__ __params__\n")228 self._file.close()229 self._all = all230 return231 def __call__(self, x, y, id=None, best=0):232 self._file = open(self._filename,'a')233 super(LoggingSow,self).__call__(x, y, id)234 if int(self._step % self._yinterval) == 0:235 if not list_or_tuple_or_ndarray(y):236 y = "%f" % self._y[-1]237 elif self._all:238 y = "%s" % self._y[-1]239 else:240 y = "%f" % self._y[-1][best]241 if not list_or_tuple_or_ndarray(x):242 x = "[%f]" % self._x[-1]243 elif self._all:244 xa = self._x[-1]245 if not list_or_tuple_or_ndarray(xa):246 x = "[%f]" % xa247 else:248 x = "%s" % xa249 else:250 xb = self._x[-1][best]251 if not list_or_tuple_or_ndarray(xb):252 x = "[%f]" % xb253 else:254 x = "%s" % xb255 step = [self._step]256 if id != None: step.append(id)257 self._file.write(" %s %s %s\n" % (tuple(step), y, x))258 self._step += 1259 self._file.close()260 return261 pass262 263 def CustomSow(*args,**kwds):264 """265 generate a custom Sow266 267 takes *args & **kwds, where args will be required inputs for the Sow::268 - args: property name strings (i.e. 'x')269 - kwds: must be in the form: property="doc" (i.e. x='Params')270 271 example usage...272 >>> sow = CustomSow('x','y',x="Params",y="Costs",e="Error",d="Deriv")273 >>> sow(1,1)274 >>> sow(2,4,e=0)275 >>> sow.x276 [1,2]277 >>> sow.y278 [1,4]279 >>> sow.e280 [0]281 >>> sow.d282 []283 """284 from _genSow import genSow285 return genSow(**kwds)(*args)286 117 287 118 def random_seed(s): … … 436 267 437 268 269 # backward compatibility 270 from monitors import Monitor as Sow 271 from monitors import VerboseMonitor as VerboseSow 272 from monitors import LoggingMonitor as LoggingSow 273 from monitors import CustomMonitor as CustomSow 274 275 438 276 if __name__=='__main__': 439 277 import doctest -
mystic/scripts/mystic_log_reader.py
r436 r466 1 1 #!/usr/bin/env python 2 2 __doc__ = """ 3 plot parameter convergence from file written with 'Logging Sow'3 plot parameter convergence from file written with 'LoggingMonitor' 4 4 5 5 Usage: python log_reader.py [filename] [maxiter] -
mystic/tests/solver_test_best_performance.py
r465 r466 3 3 adjusted to achieve the best results. 4 4 """ 5 from mystic.tools import random_seed, Sow 5 from mystic.monitors import Monitor 6 from mystic.tools import random_seed 6 7 random_seed(123) 7 8 import time … … 57 58 from mystic.termination import ChangeOverGeneration as COG 58 59 from mystic.strategy import Rand1Bin 59 esow = Sow()60 ssow = Sow()60 esow = Monitor() 61 ssow = Monitor() 61 62 solver = DifferentialEvolutionSolver(ndim, npop) 62 63 solver.SetInitialPoints(x0) … … 81 82 from mystic.termination import ChangeOverGeneration as COG 82 83 from mystic.strategy import Rand1Bin 83 esow = Sow()84 ssow = Sow()84 esow = Monitor() 85 ssow = Monitor() 85 86 solver = DifferentialEvolutionSolver2(ndim, npop) 86 87 solver.SetInitialPoints(x0) … … 103 104 from mystic.solvers import NelderMeadSimplexSolver 104 105 from mystic.termination import CandidateRelativeTolerance as CRT 105 esow = Sow()106 ssow = Sow()106 esow = Monitor() 107 ssow = Monitor() 107 108 solver = NelderMeadSimplexSolver(ndim) 108 109 solver.SetInitialPoints(x0) … … 124 125 from mystic.solvers import PowellDirectionalSolver 125 126 from mystic.termination import NormalizedChangeOverGeneration as NCOG 126 esow = Sow()127 ssow = Sow()127 esow = Monitor() 128 ssow = Monitor() 128 129 solver = PowellDirectionalSolver(ndim) 129 130 solver.SetInitialPoints(x0) … … 184 185 from mystic.termination import VTR 185 186 from mystic.strategy import Rand1Bin, Best1Bin, Rand1Exp 186 esow = Sow()187 ssow = Sow()187 esow = Monitor() 188 ssow = Monitor() 188 189 solver = DifferentialEvolutionSolver(ndim, npop) 189 190 solver.SetRandomInitialPoints(lb, ub) … … 214 215 from mystic.termination import VTR 215 216 from mystic.strategy import Rand1Bin, Best1Bin, Rand1Exp 216 esow = Sow()217 ssow = Sow()217 esow = Monitor() 218 ssow = Monitor() 218 219 solver = DifferentialEvolutionSolver2(ndim, npop) 219 220 solver.SetRandomInitialPoints(lb, ub) -
mystic/tests/solver_test_suite.py
r465 r466 29 29 30 30 def _run_solver(self, iter_limit=False, local=False, **kwds): 31 from mystic. tools import Sow31 from mystic.monitors import Monitor 32 32 import numpy 33 33 from mystic.tools import random_seed 34 34 random_seed(123) # Number of failures is quite dependent on random seed! 35 esow = Sow()36 ssow = Sow()35 esow = Monitor() 36 ssow = Monitor() 37 37 38 38 if iter_limit: # CRT with solvers that don't use population. … … 239 239 240 240 def _run_solver(self, iter_limit=False, **kwds): 241 from mystic. tools import Sow241 from mystic.monitors import Monitor 242 242 import numpy 243 243 from mystic.tools import random_seed 244 244 #random_seed(123) 245 esow = Sow()246 ssow = Sow()245 esow = Monitor() 246 ssow = Monitor() 247 247 248 248 solver = self.solver … … 439 439 440 440 def _run_solver(self, iter_limit=False, **kwds): 441 from mystic. tools import Sow441 from mystic.monitors import Monitor 442 442 import numpy 443 443 from mystic.tools import random_seed 444 444 random_seed(123) 445 esow = Sow()446 ssow = Sow()445 esow = Monitor() 446 ssow = Monitor() 447 447 448 448 solver = self.solver … … 639 639 640 640 def _run_solver(self, iter_limit=False, **kwds): 641 from mystic. tools import Sow641 from mystic.monitors import Monitor 642 642 import numpy 643 643 from mystic.tools import random_seed 644 644 #random_seed(123) 645 esow = Sow()646 ssow = Sow()645 esow = Monitor() 646 ssow = Monitor() 647 647 648 648 solver = self.solver … … 837 837 838 838 def _run_solver(self, iter_limit=False, **kwds): 839 from mystic. tools import Sow839 from mystic.monitors import Monitor 840 840 import numpy 841 841 from mystic.tools import random_seed 842 842 random_seed(123) 843 esow = Sow()844 ssow = Sow()843 esow = Monitor() 844 ssow = Monitor() 845 845 846 846 solver = self.solver … … 1036 1036 1037 1037 def _run_solver(self, iter_limit = False, **kwds): 1038 from mystic. tools import Sow1038 from mystic.monitors import Monitor 1039 1039 import numpy 1040 1040 from mystic.tools import random_seed 1041 1041 #random_seed(123) 1042 esow = Sow()1043 ssow = Sow()1042 esow = Monitor() 1043 ssow = Monitor() 1044 1044 1045 1045 solver = self.solver … … 1236 1236 1237 1237 def _run_solver(self, iter_limit=False, **kwds): 1238 from mystic. tools import Sow1238 from mystic.monitors import Monitor 1239 1239 import numpy 1240 1240 from mystic.tools import random_seed 1241 1241 #random_seed(123) 1242 esow = Sow()1243 ssow = Sow()1242 esow = Monitor() 1243 ssow = Monitor() 1244 1244 1245 1245 solver = self.solver … … 1448 1448 1449 1449 def _run_solver(self, iter_limit=False, **kwds): 1450 from mystic. tools import Sow1450 from mystic.monitors import Monitor 1451 1451 import numpy 1452 1452 from mystic.tools import random_seed 1453 1453 #random_seed(123) 1454 esow = Sow()1455 ssow = Sow()1454 esow = Monitor() 1455 ssow = Monitor() 1456 1456 1457 1457 solver = self.solver … … 1659 1659 1660 1660 def _run_solver(self, iter_limit=False, **kwds): 1661 from mystic. tools import Sow1661 from mystic.monitors import Monitor 1662 1662 import numpy 1663 1663 from mystic.tools import random_seed 1664 1664 #random_seed(123) 1665 esow = Sow()1666 ssow = Sow()1665 esow = Monitor() 1666 ssow = Monitor() 1667 1667 1668 1668 solver = self.solver … … 1867 1867 1868 1868 def _run_solver(self, iter_limit=False, **kwds): 1869 from mystic. tools import Sow1869 from mystic.monitors import Monitor 1870 1870 import numpy 1871 1871 from mystic.tools import random_seed 1872 1872 random_seed(123) 1873 esow = Sow()1874 ssow = Sow()1873 esow = Monitor() 1874 ssow = Monitor() 1875 1875 1876 1876 solver = self.solver … … 2073 2073 2074 2074 def _run_solver(self, iter_limit=False, **kwds): 2075 from mystic. tools import Sow2075 from mystic.monitors import Monitor 2076 2076 import numpy 2077 2077 from mystic.tools import random_seed 2078 2078 random_seed(123) 2079 esow = Sow()2080 ssow = Sow()2079 esow = Monitor() 2080 ssow = Monitor() 2081 2081 2082 2082 solver = self.solver … … 2284 2284 2285 2285 def _run_solver(self, iter_limit=False, **kwds): 2286 from mystic. tools import Sow2286 from mystic.monitors import Monitor 2287 2287 import numpy 2288 2288 from mystic.tools import random_seed 2289 2289 random_seed(123) 2290 esow = Sow()2291 ssow = Sow()2290 esow = Monitor() 2291 ssow = Monitor() 2292 2292 2293 2293 solver = self.solver … … 2490 2490 2491 2491 def _run_solver(self, iter_limit=False, **kwds): 2492 from mystic. tools import Sow2492 from mystic.monitors import Monitor 2493 2493 import numpy 2494 2494 from mystic.tools import random_seed 2495 2495 random_seed(123) 2496 esow = Sow()2497 ssow = Sow()2496 esow = Monitor() 2497 ssow = Monitor() 2498 2498 2499 2499 solver = self.solver … … 2695 2695 2696 2696 def _run_solver(self, iter_limit=False, **kwds): 2697 from mystic. tools import Sow2697 from mystic.monitors import Monitor 2698 2698 import numpy 2699 2699 from mystic.tools import random_seed 2700 2700 random_seed(123) 2701 esow = Sow()2702 ssow = Sow()2701 esow = Monitor() 2702 ssow = Monitor() 2703 2703 2704 2704 solver = self.solver … … 2901 2901 2902 2902 def _run_solver(self, iter_limit=False, **kwds): 2903 from mystic. tools import Sow2903 from mystic.monitors import Monitor 2904 2904 import numpy 2905 2905 from mystic.tools import random_seed 2906 2906 random_seed(123) 2907 esow = Sow()2908 ssow = Sow()2907 esow = Monitor() 2908 ssow = Monitor() 2909 2909 2910 2910 solver = self.solver … … 3111 3111 3112 3112 def _run_solver(self, iter_limit=False, **kwds): 3113 from mystic. tools import Sow3113 from mystic.monitors import Monitor 3114 3114 import numpy 3115 3115 from mystic.tools import random_seed 3116 3116 random_seed(123) 3117 esow = Sow()3118 ssow = Sow()3117 esow = Monitor() 3118 ssow = Monitor() 3119 3119 3120 3120 solver = self.solver … … 3325 3325 3326 3326 def _run_solver(self, iter_limit=False, **kwds): 3327 from mystic. tools import Sow3327 from mystic.monitors import Monitor 3328 3328 import numpy 3329 3329 from mystic.tools import random_seed 3330 3330 random_seed(123) 3331 esow = Sow()3332 ssow = Sow()3331 esow = Monitor() 3332 ssow = Monitor() 3333 3333 3334 3334 solver = self.solver -
mystic/tests/test_SOW.py
r465 r466 92 92 if __name__ == '__main__': 93 93 94 from mystic. tools import Sow, VerboseSow, LoggingSow95 #monitor = Sow()96 #monitor = Sow(all=True)97 #monitor = Sow(all=False)98 #monitor = Verbose Sow(1,1)99 #monitor = Verbose Sow(1,1, all=True)100 #monitor = Verbose Sow(1,1, all=False)101 monitor = Logging Sow(1)102 #monitor = Logging Sow(1, all=True)103 #monitor = Logging Sow(1, all=False)94 from mystic.monitors import Monitor, VerboseMonitor, LoggingMonitor 95 #monitor = Monitor() 96 #monitor = Monitor(all=True) 97 #monitor = Monitor(all=False) 98 #monitor = VerboseMonitor(1,1) 99 #monitor = VerboseMonitor(1,1, all=True) 100 #monitor = VerboseMonitor(1,1, all=False) 101 monitor = LoggingMonitor(1) 102 #monitor = LoggingMonitor(1, all=True) 103 #monitor = LoggingMonitor(1, all=False) 104 104 105 105 #test0(monitor) … … 109 109 #test2(monitor, diffenv=True) 110 110 111 # these are for " SowPlotter(s)"; need to adapt log.py plotters for test1111 # these are for "MonitorPlotter(s)"; need to adapt log.py plotters for test1 112 112 write_support_file(monitor,'paramlog1.py') 113 113 #write_converge_file(monitor,'paramlog2.py')
Note: See TracChangeset
for help on using the changeset viewer.