Changeset 851
- Timestamp:
- 12/29/15 18:57:21 (5 months ago)
- Location:
- mystic
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
mystic/mystic/constraints.py
r823 r851 304 304 and less accurate than writing the constraints solver from scratch. 305 305 306 NOTE: The ensemble solvers are available, using the default NestedSolver, 307 where the keyword 'guess' can be used to set the number of solvers. 308 306 309 NOTE: The default solver is 'diffev', with npop=min(40, ndim*5). The default 307 310 termination is ChangeOverGeneration(), and the default guess is randomly 308 311 selected points between the upper and lower bounds. 309 312 """ 313 npts = 8 314 if type(guess) is int: npts, guess = guess, None 315 310 316 ndim = 1 #XXX: better, increase in while loop catching IndexError ? 311 317 if nvars is not None: ndim = nvars … … 316 322 def cost(x): return 1. 317 323 318 #XXX: don't allow solver string as a short-cut? 324 #XXX: don't allow solver string as a short-cut? #FIXME: add ensemble solvers 325 ensemble = False 319 326 if solver is None or solver == 'diffev': 320 327 from mystic.solvers import DifferentialEvolutionSolver as TheSolver … … 329 336 from mystic.solvers import NelderMeadSimplexSolver as TheSolver 330 337 solver = TheSolver(ndim) 338 elif solver == 'buckshot': 339 from mystic.solvers import BuckshotSolver as TheSolver 340 solver = TheSolver(ndim, max(8, npts)) #XXX: needs better default? 341 ensemble = True 342 elif solver == 'lattice': 343 from mystic.solvers import LatticeSolver as TheSolver 344 solver = TheSolver(ndim, max(8, npts)) #XXX: needs better default? 345 ensemble = True 331 346 332 347 if termination is None: 333 348 from mystic.termination import ChangeOverGeneration as COG 334 349 termination = COG() 335 if guess is not None: 336 solver.SetInitialPoints(guess) #XXX: nice if 'diffev' also had methods 337 else: 338 solver.SetRandomInitialPoints(lower_bounds, upper_bounds) 350 if not ensemble: 351 if guess is not None: 352 solver.SetInitialPoints(guess) #XXX: nice if 'diffev' had methods 353 else: 354 solver.SetRandomInitialPoints(lower_bounds, upper_bounds) 339 355 if lower_bounds or upper_bounds: 340 356 solver.SetStrictRanges(lower_bounds, upper_bounds) -
mystic/tests/test_constraints.py
r776 r851 55 55 56 56 x = solve(penalty, guess=[2,3,1]) 57 #x = solve(penalty, solver='buckshot') 57 58 58 59 assert round(mean_constraint(x, 5.0)) == 0.0 … … 70 71 71 72 x = solve(constraint, guess=[2,3,1]) 73 #x = solve(constraint, solver='buckshot') 72 74 73 75 assert almostEqual(mean(x), 1.0, tol=1e-15)
Note: See TracChangeset
for help on using the changeset viewer.