Changeset 111


Ignore:
Timestamp:
03/11/09 11:33:05 (7 years ago)
Author:
mmckerns
Message:

created SetEvaluationLimits? method in abstract_solver;
propagated changes to the derived solvers and examples;
removed 'ooe' circle branch... it's in the trunk now

Files:
1 deleted
26 edited

Legend:

Unmodified
Added
Removed
  • mystic/MYSTIC-EXAMPLE.txt

    r88 r111  
    131131    solver.SetRandomInitialPoints(min = minrange, max = maxrange) 
    132132    solver.SetStrictRanges(min = minrange, max = maxrange) 
     133    solver.SetEvaluationLimits(maxiter=MAX_GENERATIONS) 
    133134 
    134135    solver.Solve(CF,Best1Exp,termination=ChangeOverGeneration(generations=300),\ 
    135                 maxiter=MAX_GENERATIONS,CrossProbability=0.5,ScalingFactor=0.5,\ 
    136                 StepMonitor=stepmon,sigint_callback=plot_sol) 
     136                 CrossProbability=0.5,ScalingFactor=0.5,\ 
     137                 StepMonitor=stepmon,sigint_callback=plot_sol) 
    137138 
    138139    solution = solver.Solution() 
  • mystic/examples/derun.py

    r95 r111  
    5252        strategy  = self.strategy 
    5353        solver.SetRandomInitialPoints(min = self.mod.min, max = self.mod.max) 
    54         solver.Solve(costfunction, strategy, termination, CrossProbability=self.probability, \ 
    55                      maxiter = MAX_GENERATIONS,ScalingFactor=self.scale) 
     54        solver.SetEvaluationLimits(maxiter=MAX_GENERATIONS) 
     55        solver.Solve(costfunction, strategy, termination,\ 
     56                     CrossProbability=self.probability, \ 
     57                     ScalingFactor=self.scale) 
    5658        self.solution = solver.Solution() 
    5759        return 
  • mystic/examples/example_getCost.py

    r95 r111  
    3434    solver.SetRandomInitialPoints(min = minrange, max = maxrange) 
    3535    solver.SetStrictRanges(min = minrange, max = maxrange) 
     36    solver.SetEvaluationLimits(maxiter=MAX_GENERATIONS) 
    3637 
    3738    solver.Solve(CF,Best1Exp,termination=ChangeOverGeneration(generations=300),\ 
    38                 maxiter=MAX_GENERATIONS,CrossProbability=0.5,ScalingFactor=0.5,\ 
     39                CrossProbability=0.5,ScalingFactor=0.5,\ 
    3940                StepMonitor=stepmon,sigint_callback=plot_sol) 
    4041 
  • mystic/examples/test_br8.py

    r95 r111  
    6767    solver.SetRandomInitialPoints(min=minrange,max=maxrange) 
    6868    solver.SetStrictRanges(min=minrange, max=maxrange) 
     69    solver.SetEvaluationLimits(maxiter=MAX_GENERATIONS) 
    6970    solver.Solve(CF,Best1Exp,termination=ChangeOverGeneration(generations=50),\ 
    70                  maxiter=MAX_GENERATIONS,StepMonitor=stepmon) 
     71                 StepMonitor=stepmon) 
    7172    solution = solver.Solution() 
    7273    return solution, stepmon 
  • mystic/examples/test_circle.py

    r108 r111  
    4949solver.enable_signal_handler() 
    5050solver.SetRandomInitialPoints(min=minrange,max=maxrange) 
    51 solver.Solve(cost, Best1Exp, \ 
    52              termination=ChangeOverGeneration(generations=100), \ 
    53              maxiter=MAX_GENERATIONS) 
     51solver.SetEvaluationLimits(maxiter=MAX_GENERATIONS) 
     52solver.Solve(cost, Best1Exp, termination=ChangeOverGeneration(generations=100)) 
    5453 
    5554 
  • mystic/examples/test_corana.py

    r106 r111  
    3131 
    3232    solver.SetRandomInitialPoints(min = [-1000]*ND, max = [1000]*ND) 
     33    solver.SetEvaluationLimits(maxiter=MAX_GENERATIONS) 
    3334 
    3435    solver.Solve(Corana, Rand1Exp, termination = VTR(0.00000001) , \ 
    35                  maxiter= MAX_GENERATIONS, CrossProbability=0.5, ScalingFactor=0.9) 
     36                 CrossProbability=0.5, ScalingFactor=0.9) 
    3637 
    3738    solution = solver.Solution() 
  • mystic/examples/test_dejong3.py

    r97 r111  
    3232 
    3333    solver.SetRandomInitialPoints(min = [-5.12]*ND, max = [5.12]*ND) 
     34    solver.SetEvaluationLimits(maxiter=MAX_GENERATIONS) 
    3435 
    3536    solver.Solve(DeJong3, Best1Exp, termination = VTR(0.00001) , \ 
    36                  maxiter= MAX_GENERATIONS, CrossProbability=0.3, ScalingFactor=1.0) 
     37                 CrossProbability=0.3, ScalingFactor=1.0) 
    3738 
    3839    solution = solver.Solution() 
  • mystic/examples/test_dejong4.py

    r97 r111  
    3131 
    3232    solver.SetRandomInitialPoints(min = [-1.28]*ND, max = [1.28]*ND) 
     33    solver.SetEvaluationLimits(maxiter=MAX_GENERATIONS) 
    3334 
    3435    solver.Solve(DeJong4, Rand1Exp, termination = VTR(15) , \ 
    35                  maxiter= MAX_GENERATIONS, CrossProbability=0.3, ScalingFactor=1.0) 
     36                 CrossProbability=0.3, ScalingFactor=1.0) 
    3637 
    3738    solution = solver.Solution() 
  • mystic/examples/test_dejong5.py

    r95 r111  
    2929 
    3030    solver.SetRandomInitialPoints(min = [-65.536]*ND, max = [65.536]*ND) 
     31    solver.SetEvaluationLimits(maxiter=MAX_GENERATIONS) 
    3132 
    3233    solver.Solve(DeJong5, Rand1Exp, termination = VTR(0.0000001) , \ 
    33                  maxiter= MAX_GENERATIONS, CrossProbability=0.5, ScalingFactor=0.9) 
     34                 CrossProbability=0.5, ScalingFactor=0.9) 
    3435 
    3536    solution = solver.Solution() 
  • mystic/examples/test_ffit.py

    r109 r111  
    6363def main(): 
    6464    solver = DifferentialEvolutionSolver(ND, NP) 
    65  
    6665    solver.SetRandomInitialPoints(min = [-100.0]*ND, max = [100.0]*ND) 
    67  
     66    solver.SetEvaluationLimits(maxiter=MAX_GENERATIONS) 
    6867    solver.enable_signal_handler() 
    6968   
     
    7271 
    7372    solver.Solve(ChebyshevCost, strategy, termination = VTR(0.01) , \ 
    74                  maxiter= MAX_GENERATIONS, CrossProbability=1.0, ScalingFactor=0.9 , \ 
    75                  StepMonitor=VerboseSow(30), sigint_callback = plot_solution \ 
    76                  ) 
     73                 CrossProbability=1.0, ScalingFactor=0.9 , \ 
     74                 StepMonitor=VerboseSow(30), sigint_callback=plot_solution) 
    7775 
    7876    solution = solver.Solution() 
    79  
    8077    return solution 
    8178   
  • mystic/examples/test_ffit2.py

    r98 r111  
    4040def main(): 
    4141    solver = DifferentialEvolutionSolver(ND, NP) 
    42  
    4342    solver.SetRandomInitialPoints(min = [-1000.0]*ND, max = [1000.0]*ND) 
     43    solver.SetEvaluationLimits(maxiter=MAX_GENERATIONS) 
    4444   
    4545    #strategy = Best1Exp 
     
    4949 
    5050    solver.Solve(ChebyshevCost, strategy, termination = VTR(0.0001) , \ 
    51                  StepMonitor=VerboseSow(1), maxiter= MAX_GENERATIONS, CrossProbability=1.0, ScalingFactor=0.6) 
     51                 StepMonitor=VerboseSow(1), CrossProbability=1.0, ScalingFactor=0.6) 
    5252 
    5353    solution = solver.Solution() 
  • mystic/examples/test_ffitB.py

    r110 r111  
    1818 
    1919    solver = DifferentialEvolutionSolver(ND, NP) 
    20  
    2120    solver.SetRandomInitialPoints(min = [-100.0]*ND, max = [100.0]*ND) 
    22  
     21    solver.SetEvaluationLimits(maxiter=MAX_GENERATIONS) 
    2322    solver.enable_signal_handler() 
    2423   
     
    2726 
    2827    solver.Solve(ChebyshevCost, strategy, termination = VTR(0.01) , \ 
    29                  maxiter= MAX_GENERATIONS, CrossProbability=1.0, ScalingFactor=0.9 , \ 
    30                  StepMonitor=VerboseSow(30), sigint_callback = plot_solution \ 
    31                  ) 
     28                 CrossProbability=1.0, ScalingFactor=0.9 , \ 
     29                 StepMonitor=VerboseSow(30), sigint_callback=plot_solution) 
    3230 
    3331    solution = solver.Solution() 
  • mystic/examples/test_fosc3d.py

    r106 r111  
    3333def main(): 
    3434    solver = DifferentialEvolutionSolver(ND, NP) 
    35  
    3635    solver.SetRandomInitialPoints(min = [-2.0]*ND, max = [2.0]*ND) 
     36    solver.SetEvaluationLimits(maxiter=MAX_GENERATIONS) 
    3737   
    3838    strategy = Best1Exp 
     
    4040 
    4141    solver.Solve(fOsc3D,strategy,termination=ChangeOverGeneration(1e-5, 30), \ 
    42                  maxiter=MAX_GENERATIONS,CrossProbability=1.0,ScalingFactor=0.9) 
     42                 CrossProbability=1.0,ScalingFactor=0.9) 
    4343 
    4444    return solver.Solution() 
  • mystic/examples/test_griewangk.py

    r97 r111  
    3030def main(): 
    3131    solver = DifferentialEvolutionSolver(ND, NP) 
    32  
    3332    solver.SetRandomInitialPoints(min = [-400.0]*ND, max = [400.0]*ND) 
     33    solver.SetEvaluationLimits(maxiter=MAX_GENERATIONS) 
    3434 
    3535    solver.Solve(Griewangk_cost, Rand1Exp, termination = VTR(0.00001) , \ 
    36                  maxiter= MAX_GENERATIONS, CrossProbability=0.3, ScalingFactor=1.0) 
     36                 CrossProbability=0.3, ScalingFactor=1.0) 
    3737 
    3838    solution = solver.Solution() 
  • mystic/examples/test_lorentzian.py

    r94 r111  
    5555    solver.SetRandomInitialPoints(min=minrange,max=maxrange) 
    5656    solver.SetStrictRanges(min=minrange,max=maxrange) 
     57    solver.SetEvaluationLimits(maxiter=MAX_GENERATIONS) 
    5758    termination=ChangeOverGeneration(generations=generations) 
    5859    solver.Solve(CF, Rand1Exp, termination=termination, \ 
    59                  maxiter=MAX_GENERATIONS, StepMonitor=stepmon, sigint_callback = plot_sol(solver)) 
     60                 StepMonitor=stepmon, sigint_callback = plot_sol(solver)) 
    6061    solution = solver.Solution() 
    6162    return solution, stepmon 
  • mystic/examples/test_lorentzian2.py

    r95 r111  
    5656    solver.SetRandomInitialPoints(min=minrange,max=maxrange) 
    5757    solver.SetStrictRanges(min=minrange,max=maxrange) 
     58    solver.SetEvaluationLimits(maxiter=MAX_GENERATIONS) 
    5859    termination=ChangeOverGeneration(generations=generations) 
    5960    solver.Solve(CF, Rand1Exp, termination=termination, \ 
    60                  maxiter=MAX_GENERATIONS, StepMonitor=stepmon, sigint_callback = plot_sol(solver)) 
     61                 StepMonitor=stepmon, sigint_callback = plot_sol(solver)) 
    6162    solution = solver.Solution() 
    6263    return solution, stepmon 
  • mystic/examples/test_mogi.py

    r102 r111  
    8787    maxrange = [1000., 1000., 100., 10.]; 
    8888    solver.SetRandomInitialPoints(min = minrange, max = maxrange) 
     89    solver.SetEvaluationLimits(maxiter=MAX_GENERATIONS) 
    8990 
    9091   #termination = VTR(0.0000029) 
     
    9293 
    9394    solver.Solve(cost_function, Best1Exp, termination=termination, \ 
    94                  maxiter=MAX_GENERATIONS, CrossProbability=0.5, \ 
    95                  ScalingFactor=0.5, StepMonitor = stepmon) 
     95                 CrossProbability=0.5, ScalingFactor=0.5, StepMonitor=stepmon) 
    9696 
    9797    solution = solver.Solution() 
  • mystic/examples/test_mogi2.py

    r88 r111  
    7575    maxrange = [1000., 1000., 100., 1.]*2; 
    7676    solver.SetRandomInitialPoints(min = minrange, max = maxrange) 
     77    solver.SetEvaluationLimits(maxiter=MAX_GENERATIONS) 
    7778 
    78     solver.Solve(cost_function, Best1Exp, termination = ChangeOverGeneration(generations=300) , \ 
    79                  maxiter= MAX_GENERATIONS, CrossProbability=0.5, ScalingFactor=0.5, \ 
     79    solver.Solve(cost_function, Best1Exp,\ 
     80                 termination = ChangeOverGeneration(generations=300) , \ 
     81                 CrossProbability=0.5, ScalingFactor=0.5, \ 
    8082                 StepMonitor = stepmon, sigint_callback = plot_sol) 
    8183 
  • mystic/examples/test_mogi3.py

    r94 r111  
    1919    maxrange = [1000., 1000., 100., 10.]; 
    2020    solver.SetRandomInitialPoints(min = minrange, max = maxrange) 
     21    solver.SetEvaluationLimits(maxiter=MAX_GENERATIONS) 
    2122 
    22     solver.Solve(CF, Best1Exp, termination = ChangeOverGeneration(generations=100) , \ 
    23                  maxiter= MAX_GENERATIONS, CrossProbability=0.5, ScalingFactor=0.5, \ 
     23    solver.Solve(CF, Best1Exp,\ 
     24                 termination = ChangeOverGeneration(generations=100) , \ 
     25                 CrossProbability=0.5, ScalingFactor=0.5, \ 
    2426                 StepMonitor = stepmon) 
    2527 
  • mystic/examples/test_mogi4.py

    r95 r111  
    2323    maxrange = [1000., 1000., 100., 1.]*2; 
    2424    solver.SetRandomInitialPoints(min = minrange, max = maxrange) 
     25    solver.SetEvaluationLimits(maxiter=MAX_GENERATIONS) 
    2526 
    26     solver.Solve(CF, Best1Exp, termination = ChangeOverGeneration(generations=300) , \ 
    27                  maxiter= MAX_GENERATIONS, CrossProbability=0.5, ScalingFactor=0.5, \ 
     27    solver.Solve(CF, Best1Exp,\ 
     28                 termination = ChangeOverGeneration(generations=300) , \ 
     29                 CrossProbability=0.5, ScalingFactor=0.5, \ 
    2830                 StepMonitor = stepmon, sigint_callback = plot_sol) 
    2931 
  • mystic/examples/test_rosenbrock.py

    r102 r111  
    3030 
    3131    solver.SetRandomInitialPoints(min = [0]*ND, max = [2]*ND) 
     32    solver.SetEvaluationLimits(maxiter=MAX_GENERATIONS) 
    3233 
    3334    solver.Solve(rosen, Best1Exp, termination = VTR(0.0001) , \ 
    34                  maxiter= MAX_GENERATIONS, CrossProbability=0.5, ScalingFactor=0.6) 
     35                 CrossProbability=0.5, ScalingFactor=0.6) 
    3536 
    3637    solution = solver.Solution() 
  • mystic/examples/test_wavy.py

    r106 r111  
    4646def main(): 
    4747    solver = DifferentialEvolutionSolver(ND, NP) 
    48  
    4948    solver.SetRandomInitialPoints(min = [-100.0]*ND, max = [100.0]*ND) 
     49    solver.SetEvaluationLimits(maxiter=MAX_GENERATIONS) 
    5050 
    5151    solver.enable_signal_handler() 
    52    
     52 
    5353    strategy = Best1Bin 
    54  
    5554    stepmon = VerboseSow(1) 
    56     solver.Solve(wavy, strategy, termination = ChangeOverGeneration(generations=50) , \ 
    57                  maxiter= MAX_GENERATIONS, CrossProbability=1.0, ScalingFactor=0.9 , \ 
    58                  StepMonitor = stepmon,  sigint_callback = plot_solution \ 
    59                  ) 
     55    solver.Solve(wavy, strategy,\ 
     56                 termination = ChangeOverGeneration(generations=50) , \ 
     57                 CrossProbability=1.0, ScalingFactor=0.9 , \ 
     58                 StepMonitor = stepmon,  sigint_callback = plot_solution) 
    6059 
    6160    solution = solver.Solution() 
  • mystic/examples/test_zimmermann.py

    r102 r111  
    3434 
    3535    solver.SetRandomInitialPoints(min = [0.]*ND, max = [5.]*ND) 
     36    solver.SetEvaluationLimits(maxiter=MAX_GENERATIONS) 
    3637 
    3738    solver.Solve(CostFunction, Rand1Exp, termination = VTR(0.0000001) , \ 
    38                  maxiter= MAX_GENERATIONS, CrossProbability=0.3, ScalingFactor=1.0) 
     39                 CrossProbability=0.3, ScalingFactor=1.0) 
    3940 
    4041    solution = solver.Solution() 
  • mystic/mystic/abstract_solver.py

    r105 r111  
    4949        self._strictMin       = [] 
    5050        self._strictMax       = [] 
     51        self._maxiter         = None 
     52        self._maxfun          = None 
    5153 
    5254 
     
    152154        self._handle_sigint = False 
    153155 
    154     def Solve(self, func, termination, 
    155               maxiter=None, maxfun=None, sigint_callback=None, 
     156    def SetEvaluationLimits(self,*args,**kwds): 
     157        """set limits for maxiter and/or maxfun 
     158  - maxiter = maximum number of solver iterations (i.e. steps) 
     159  - maxfun  = maximum number of function evaluations""" 
     160       #self._maxiter,self._maxfun = None,None 
     161        if len(args) == 2: 
     162            self._maxiter,self._maxfun = args[0],args[1] 
     163        elif len(args) == 1: 
     164            self._maxiter = args[0] 
     165        if kwds.has_key('maxiter'): self._maxiter = kwds['maxiter'] 
     166        if kwds.has_key('maxfun'): self._maxfun = kwds['maxfun'] 
     167 
     168    def Solve(self, func, termination, sigint_callback=None, 
    156169              EvaluationMonitor=Null, StepMonitor=Null, ExtraArgs=(), **kwds): 
    157170        """solve function 'func' with given termination conditions 
  • mystic/mystic/differential_evolution.py

    r110 r111  
    8989        return 
    9090 
    91     def Solve(self, costfunction, strategy, termination, 
    92               maxiter=None, maxfun=None, sigint_callback=None, 
     91    def Solve(self, costfunction, strategy, termination, sigint_callback=None, 
    9392              CrossProbability = 0.5, ScalingFactor = 0.7, 
    9493              EvaluationMonitor=Null, StepMonitor=Null, ExtraArgs=(), **kwds): 
     
    163162        self.bestEnergy = 1.0E20 
    164163          
    165         if maxiter is None: 
    166             maxiter = self.nDim * self.nPop * 10  #XXX: set better defaults? 
    167         if maxfun is None: 
    168             maxfun = self.nDim * self.nPop * 1000 #XXX: set better defaults? 
    169         self._maxiter = maxiter 
    170         self._maxfun = maxfun 
     164        if self._maxiter is None: 
     165            self._maxiter = self.nDim * self.nPop * 10  #XXX: set better defaults? 
     166        if self._maxfun is None: 
     167            self._maxfun = self.nDim * self.nPop * 1000 #XXX: set better defaults? 
    171168 
    172169        generation = 0 
    173         for generation in range(maxiter): 
     170        for generation in range(self._maxiter): 
    174171            StepMonitor(self.bestSolution[:], self.bestEnergy) 
    175             if fcalls[0] >= maxfun: break 
     172            if fcalls[0] >= self._maxfun: break 
    176173            for candidate in range(self.nPop): 
    177174                # generate trialSolution (within valid range) 
     
    221218        generation is invariant during the main DE logic. 
    222219    """ 
    223     def Solve(self, costfunction, strategy, termination, 
    224               maxiter=None, maxfun=None, sigint_callback=None, 
     220    def Solve(self, costfunction, strategy, termination, sigint_callback=None, 
    225221              CrossProbability = 0.5, ScalingFactor = 0.7, 
    226222              EvaluationMonitor=Null, StepMonitor=Null, ExtraArgs=(), **kwds): 
     
    293289        self.bestEnergy = 1.0E20 
    294290          
    295         if maxiter is None: 
    296             maxiter = self.nDim * self.nPop * 10  #XXX: set better defaults? 
    297         if maxfun is None: 
    298             maxfun = self.nDim * self.nPop * 1000 #XXX: set better defaults? 
    299         self._maxiter = maxiter 
    300         self._maxfun = maxfun 
    301  
     291        if self._maxiter is None: 
     292            self._maxiter = self.nDim * self.nPop * 10  #XXX: set better defaults? 
     293        if self._maxfun is None: 
     294            self._maxfun = self.nDim * self.nPop * 1000 #XXX: set better defaults? 
    302295        trialPop = [[0.0 for i in range(self.nDim)] for j in range(self.nPop)] 
    303296 
    304297        generation = 0 
    305         for generation in range(maxiter): 
     298        for generation in range(self._maxiter): 
    306299            StepMonitor(self.bestSolution[:], self.bestEnergy) 
    307             if fcalls[0] >= maxfun: break 
     300            if fcalls[0] >= self._maxfun: break 
    308301            for candidate in range(self.nPop): 
    309302                # generate trialSolution (within valid range) 
     
    361354    ND = len(x0) 
    362355    solver = DifferentialEvolutionSolver2(ND,npop) 
     356    solver.SetEvaluationLimits(maxiter,maxfun) 
    363357    if bounds: 
    364358        minb,maxb = unpair(bounds) 
     
    372366 
    373367   #solver.enable_signal_handler() 
    374     #XXX: move maxiter & maxfun kwds from Solve() to solver.SetLimits() ? 
    375368    #TODO: enable signal handlers & sigint_callbacks? for all minimal interfaces 
    376369    #FIXME: DESolve can't handle bounds of numpy.inf 
    377370    solver.Solve(func,strategy=strategy,termination=termination,\ 
    378                  maxiter=maxiter,maxfun=maxfun,\ 
     371                #sigint_callback=other_callback,\ 
    379372                 CrossProbability=cross,ScalingFactor=scale,\ 
    380373                 EvaluationMonitor=evalmon,StepMonitor=stepmon,\ 
    381                 #sigint_callback=other_callback,\ 
    382374                 ExtraArgs=args,callback=callback) 
    383375    solution = solver.Solution() 
  • mystic/mystic/scipy_optimize.py

    r109 r111  
    9595        return x0, val 
    9696 
    97     def Solve(self, func, termination, 
    98               maxiter=None, maxfun=None, sigint_callback=None, 
     97    def Solve(self, func, termination, sigint_callback=None, 
    9998              EvaluationMonitor=Null, StepMonitor=Null, ExtraArgs=(), **kwds): 
    10099        """Minimize a function using the downhill simplex algorithm. 
     
    112111    Additional Inputs: 
    113112 
    114       maxiter -- the maximum number of iterations to perform. 
    115       maxfun -- the maximum number of function evaluations. 
    116113      sigint_callback -- callback function for signal handler. 
    117114      EvaluationMonitor -- a callable object that will be passed x, fval 
     
    193190        if not -1 < rank < 2: 
    194191            raise ValueError, "Initial guess must be a scalar or rank-1 sequence." 
    195         if maxiter is None: 
    196             maxiter = N * 200 
    197         if maxfun is None: 
    198             maxfun = N * 200 
    199         self._maxiter = maxiter #XXX: better to just copy the code? 
    200         self._maxfun = maxfun   #XXX: better to just copy the code? 
     192        if self._maxiter is None: 
     193            self._maxiter = N * 200 
     194        if self._maxfun is None: 
     195            self._maxfun = N * 200 
    201196 
    202197        rho = 1; chi = 2; psi = 0.5; sigma = 0.5; 
     
    235230        iterations = 1 
    236231 
    237         while (fcalls[0] < maxfun and iterations < maxiter): 
     232        while (fcalls[0] < self._maxfun and iterations < self._maxiter): 
    238233            StepMonitor(sim, fsim) # get all values; "best" is sim[0] 
    239234            if detools.EARLYEXIT or termination(self): 
     
    309304        warnflag = 0 
    310305 
    311         if fcalls[0] >= maxfun: 
     306        if fcalls[0] >= self._maxfun: 
    312307            warnflag = 1 
    313308            if disp: 
    314309                print "Warning: Maximum number of function evaluations has "\ 
    315310                  "been exceeded." 
    316         elif iterations >= maxiter: 
     311        elif iterations >= self._maxiter: 
    317312            warnflag = 2 
    318313            if disp: 
     
    350345    solver.SetInitialPoints(x0) 
    351346   #solver.enable_signal_handler() 
     347    solver.SetEvaluationLimits(maxiter,maxfun) 
    352348    solver.Solve(func,termination=CRT(xtol,ftol),\ 
    353                  maxiter=maxiter,maxfun=maxfun,\ 
    354349                 EvaluationMonitor=evalmon,StepMonitor=stepmon,\ 
    355350                 disp=disp, ExtraArgs=args, callback=callback) 
     
    411406 
    412407 
    413     def Solve(self, func, termination, 
    414               maxiter=None, maxfun=None, sigint_callback=None, 
     408    def Solve(self, func, termination, sigint_callback=None, 
    415409              EvaluationMonitor=Null, StepMonitor=Null, ExtraArgs=(), **kwds): 
    416410        """Minimize a function using modified Powell's method. 
     
    428422    Additional Inputs: 
    429423 
    430       maxiter -- the maximum number of iterations to perform. 
    431       maxfun -- the maximum number of function evaluations. 
    432424      sigint_callback -- callback function for signal handler. 
    433425      EvaluationMonitor -- a callable object that will be passed x, fval 
     
    515507        if not -1 < rank < 2: 
    516508            raise ValueError, "Initial guess must be a scalar or rank-1 sequence." 
    517         if maxiter is None: 
    518             maxiter = N * 1000 
    519         if maxfun is None: 
    520             maxfun = N * 1000 
    521         self._maxiter = maxiter #XXX: better to just copy the code? 
    522         self._maxfun = maxfun   #XXX: better to just copy the code? 
     509        if self._maxiter is None: 
     510            self._maxiter = N * 1000 
     511        if self._maxfun is None: 
     512            self._maxfun = N * 1000 
    523513 
    524514        if direc is None: 
     
    561551            self.energy_history.append(fval) #XXX: the 'best' for now... 
    562552            if detools.EARLYEXIT or termination(self): CONTINUE = False #break 
    563             elif fcalls[0] >= maxfun: CONTINUE = False #break 
    564             elif iter >= maxiter: CONTINUE = False #break 
     553            elif fcalls[0] >= self._maxfun: CONTINUE = False #break 
     554            elif iter >= self._maxiter: CONTINUE = False #break 
    565555 
    566556            else: # Construct the extrapolated point 
     
    596586        warnflag = 0 
    597587 
    598         if fcalls[0] >= maxfun: 
     588        if fcalls[0] >= self._maxfun: 
    599589            warnflag = 1 
    600590            if disp: 
    601591                print "Warning: Maximum number of function evaluations has "\ 
    602592                      "been exceeded." 
    603         elif iter >= maxiter: 
     593        elif iter >= self._maxiter: 
    604594            warnflag = 2 
    605595            if disp: 
     
    642632    solver.SetInitialPoints(x0) 
    643633   #solver.enable_signal_handler() 
     634    solver.SetEvaluationLimits(maxiter,maxfun) 
    644635    solver.Solve(func,termination=NCOG(ftol),\ 
    645                  maxiter=maxiter,maxfun=maxfun,\ 
    646636                 EvaluationMonitor=evalmon,StepMonitor=stepmon,\ 
    647637                 xtol=xtol, ExtraArgs=args, callback=callback, \ 
Note: See TracChangeset for help on using the changeset viewer.