Changeset 771
- Timestamp:
- 11/19/14 10:05:33 (18 months ago)
- Location:
- mystic
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
mystic/examples/buckshot_example06.py
r725 r771 75 75 random.seed(123) 76 76 ndim = 9 77 npts = 677 npts = 8 78 78 79 79 # draw frame and exact coefficients -
mystic/examples/lattice_example06.py
r722 r771 75 75 random.seed(123) 76 76 ndim = 9 77 #nbins = [1]*ndim 78 nbins = [2,1,2,1,2,1,1,1,1] 77 nbins = [2,1,2,1,2,1,2,1,1] 79 78 80 79 # draw frame and exact coefficients -
mystic/mystic/abstract_ensemble_solver.py
r769 r771 129 129 self._bestSolver = None # 'best' solver (after Solve) 130 130 self._total_evals = 0 # total function calls (after Solve) 131 if kwds.has_key('nbins'): NP = reduce(lambda x,y:x*y, nbins) 132 else: NP = npts #XXX: merge npts/nbins kwds? 133 self._allSolvers = [None for j in range(NP)] 131 134 return 132 135 -
mystic/mystic/ensemble.py
r769 r771 135 135 136 136 # run optimizer for each grid point 137 from copy import deepcopy as copy138 op = [ copy(solver) for i in range(len(initial_values))]137 from copy import deepcopy as _copy 138 op = [_copy(solver) for i in range(len(initial_values))] 139 139 #cf = [cost for i in range(len(initial_values))] 140 140 vb = [verbose for i in range(len(initial_values))] … … 144 144 # generate the local_optimize function 145 145 def local_optimize(solver, x0, rank=None, disp=False, callback=None): 146 from copy import deepcopy as _copy 147 from mystic.tools import isNull 146 148 solver.id = rank 147 149 solver.SetInitialPoints(x0) … … 150 152 max=solver._strictMax) # or lower,upper ? 151 153 solver.Solve(cost, disp=disp, callback=callback) 152 return solver 154 sm = solver._stepmon 155 em = solver._evalmon 156 if isNull(sm): sm = ([],[],[],[]) 157 else: sm = (_copy(sm._x),_copy(sm._y),_copy(sm._id),_copy(sm._info)) 158 if isNull(em): em = ([],[],[],[]) 159 else: em = (_copy(em._x),_copy(em._y),_copy(em._id),_copy(em._info)) 160 return solver, sm, em 153 161 154 162 # map:: solver = local_optimize(solver, x0, id, verbose) … … 158 166 # save initial state 159 167 self._AbstractSolver__save_state() 168 #XXX: HACK TO GET CONTENT OF ALL MONITORS 169 # reconnect monitors; save all solvers 170 from mystic.monitors import Monitor 171 while results: #XXX: option to not save allSolvers? skip this and _copy 172 _solver, _stepmon, _evalmon = results.pop() 173 sm = Monitor() 174 sm._x,sm._y,sm._id,sm._info = _stepmon 175 _solver._stepmon.extend(sm) 176 del sm 177 em = Monitor() 178 em._x,em._y,em._id,em._info = _evalmon 179 _solver._evalmon.extend(em) 180 del em 181 self._allSolvers[len(results)] = _solver 182 del results, _solver, _stepmon, _evalmon 183 #XXX: END HACK 184 160 185 # get the results with the lowest energy 161 self._bestSolver = results[0]186 self._bestSolver = self._allSolvers[0] 162 187 bestpath = self._bestSolver._stepmon 163 188 besteval = self._bestSolver._evalmon 164 189 self._total_evals = self._bestSolver.evaluations 165 for solver in results[1:]:190 for solver in self._allSolvers[1:]: 166 191 self._total_evals += solver.evaluations # add func evals 167 192 if solver.bestEnergy < self._bestSolver.bestEnergy: … … 294 319 295 320 # run optimizer for each grid point 296 from copy import deepcopy as copy297 op = [ copy(solver) for i in range(len(initial_values))]321 from copy import deepcopy as _copy 322 op = [_copy(solver) for i in range(len(initial_values))] 298 323 #cf = [cost for i in range(len(initial_values))] 299 324 vb = [verbose for i in range(len(initial_values))] … … 303 328 # generate the local_optimize function 304 329 def local_optimize(solver, x0, rank=None, disp=False, callback=None): 330 from copy import deepcopy as _copy 331 from mystic.tools import isNull 305 332 solver.id = rank 306 333 solver.SetInitialPoints(x0) … … 309 336 max=solver._strictMax) # or lower,upper ? 310 337 solver.Solve(cost, disp=disp, callback=callback) 311 return solver 338 sm = solver._stepmon 339 em = solver._evalmon 340 if isNull(sm): sm = ([],[],[],[]) 341 else: sm = (_copy(sm._x),_copy(sm._y),_copy(sm._id),_copy(sm._info)) 342 if isNull(em): em = ([],[],[],[]) 343 else: em = (_copy(em._x),_copy(em._y),_copy(em._id),_copy(em._info)) 344 return solver, sm, em 312 345 313 346 # map:: solver = local_optimize(solver, x0, id, verbose) … … 317 350 # save initial state 318 351 self._AbstractSolver__save_state() 352 #XXX: HACK TO GET CONTENT OF ALL MONITORS 353 # reconnect monitors; save all solvers 354 from mystic.monitors import Monitor 355 while results: #XXX: option to not store allSolvers? skip this & _copy 356 _solver, _stepmon, _evalmon = results.pop() 357 sm = Monitor() 358 sm._x,sm._y,sm._id,sm._info = _stepmon 359 _solver._stepmon.extend(sm) 360 del sm 361 em = Monitor() 362 em._x,em._y,em._id,em._info = _evalmon 363 _solver._evalmon.extend(em) 364 del em 365 self._allSolvers[len(results)] = _solver 366 del results, _solver, _stepmon, _evalmon 367 #XXX: END HACK 368 319 369 # get the results with the lowest energy 320 self._bestSolver = results[0]370 self._bestSolver = self._allSolvers[0] 321 371 bestpath = self._bestSolver._stepmon 322 372 besteval = self._bestSolver._evalmon 323 373 self._total_evals = self._bestSolver.evaluations 324 for solver in results[1:]:374 for solver in self._allSolvers[1:]: 325 375 self._total_evals += solver.evaluations # add func evals 326 376 if solver.bestEnergy < self._bestSolver.bestEnergy: … … 366 416 367 417 368 def lattice(cost,ndim,nbins= None,args=(),bounds=None,ftol=1e-4,maxiter=None, \418 def lattice(cost,ndim,nbins=8,args=(),bounds=None,ftol=1e-4,maxiter=None, \ 369 419 maxfun=None,full_output=0,disp=1,retall=0,callback=None,**kwds): 370 420 """Minimize a function using the lattice ensemble solver. … … 381 431 cost -- the Python function or method to be minimized. 382 432 ndim -- dimensionality of the problem. 383 nbins -- tuple of number of bins in each dimension. [default = (2,)*ndim]433 nbins -- tuple of number of bins in each dimension. [default = 8 bins total] 384 434 385 435 Additional Inputs: … … 448 498 termination = VTRChangeOverGeneration(ftol) 449 499 450 if nbins is None: nbins = 2**ndim451 452 500 solver = LatticeSolver(ndim,nbins) 453 501 solver.SetNestedSolver(_solver) #XXX: skip settings for configured solver?
Note: See TracChangeset
for help on using the changeset viewer.