def test2(monitor, diffenv=None): if diffenv == True: #from mystic.solvers import DifferentialEvolutionSolver as DE from mystic.solvers import DifferentialEvolutionSolver2 as DE elif diffenv == False: from mystic.solvers import NelderMeadSimplexSolver as noDE else: from mystic.solvers import PowellDirectionalSolver as noDE from mystic.termination import ChangeOverGeneration as COG from mystic.tools import getch, random_seed random_seed(123) lb = [-100, -100, -100] ub = [1000, 1000, 1000] ndim = len(lb) npop = 5 maxiter = 10 maxfun = 1e+6 convergence_tol = 1e-10 ngen = 100 crossover = 0.9 percent_change = 0.9 def cost(x): ax, bx, c = x return (ax)**2 - bx + c if diffenv == True: solver = DE(ndim, npop) else: solver = noDE(ndim) solver.SetRandomInitialPoints(min=lb, max=ub) solver.SetStrictRanges(min=lb, max=ub) solver.SetEvaluationLimits(maxiter, maxfun) solver.SetEvaluationMonitor(monitor) #solver.SetGenerationMonitor(monitor) tol = convergence_tol solver.Solve(cost, termination=COG(tol, ngen)) solved = solver.Solution() monitor.info("solved: %s" % solved) func_max = -solver.bestEnergy return solved, func_max
def test2(monitor, diffenv=None): if diffenv == True: #from mystic.solvers import DifferentialEvolutionSolver as DE from mystic.solvers import DifferentialEvolutionSolver2 as DE elif diffenv == False: from mystic.solvers import NelderMeadSimplexSolver as noDE else: from mystic.solvers import PowellDirectionalSolver as noDE from mystic.termination import ChangeOverGeneration as COG from mystic.tools import getch, random_seed random_seed(123) lb = [-100,-100,-100] ub = [1000,1000,1000] ndim = len(lb) npop = 5 maxiter = 10 maxfun = 1e+6 convergence_tol = 1e-10; ngen = 100 crossover = 0.9 percent_change = 0.9 def cost(x): ax,bx,c = x return (ax)**2 - bx + c if diffenv == True: solver = DE(ndim,npop) else: solver = noDE(ndim) solver.SetRandomInitialPoints(min=lb,max=ub) solver.SetStrictRanges(min=lb,max=ub) solver.SetEvaluationLimits(maxiter,maxfun) solver.SetEvaluationMonitor(monitor) #solver.SetGenerationMonitor(monitor) tol = convergence_tol solver.Solve(cost, termination=COG(tol,ngen)) solved = solver.Solution() monitor.info("solved: %s" % solved) func_max = -solver.bestEnergy return solved, func_max