def __init__(self, dim, **kwds): """ Takes one initial input:: dim -- dimensionality of the problem. Additional inputs:: npop -- size of the trial solution population. [default = 1] nbins -- tuple of number of bins in each dimension. [default = [1]*dim] npts -- number of solver instances. [default = 1] rtol -- size of radial tolerance for sparsity. [default = None] Important class members:: nDim, nPop = dim, npop generations - an iteration counter. evaluations - an evaluation counter. bestEnergy - current best energy. bestSolution - current best parameter set. [size = dim] popEnergy - set of all trial energy solutions. [size = npop] population - set of all trial parameter solutions. [size = dim*npop] solution_history - history of bestSolution status. [StepMonitor.x] energy_history - history of bestEnergy status. [StepMonitor.y] signal_handler - catches the interrupt signal. [***disabled***] """ super(AbstractEnsembleSolver, self).__init__(dim, **kwds) #self.signal_handler = None #self._handle_sigint = False # default settings for nested optimization #XXX: move nbins and npts to _InitialPoints? self._dist = None #kwds['dist'] if 'dist' in kwds else None nbins = kwds['nbins'] if 'nbins' in kwds else [1] * dim if isinstance(nbins, int): from mystic.math.grid import randomly_bin nbins = randomly_bin(nbins, dim, ones=True, exact=True) self._nbins = nbins npts = kwds['npts'] if 'npts' in kwds else 1 self._npts = npts rtol = kwds['rtol'] if 'rtol' in kwds else None self._rtol = rtol from mystic.solvers import NelderMeadSimplexSolver self._solver = NelderMeadSimplexSolver self._bestSolver = None # 'best' solver (after Solve) self._total_evals = 0 # total function calls (after Solve) NP = reduce(lambda x, y: x * y, nbins) if 'nbins' in kwds else npts self._allSolvers = [None for j in range(NP)] return
def __init__(self, dim, **kwds): """ Takes one initial input:: dim -- dimensionality of the problem. Additional inputs:: npop -- size of the trial solution population. [default = 1] nbins -- tuple of number of bins in each dimension. [default = [1]*dim] npts -- number of solver instances. [default = 1] rtol -- size of radial tolerance for sparsity. [default = None] Important class members:: nDim, nPop = dim, npop generations - an iteration counter. evaluations - an evaluation counter. bestEnergy - current best energy. bestSolution - current best parameter set. [size = dim] popEnergy - set of all trial energy solutions. [size = npop] population - set of all trial parameter solutions. [size = dim*npop] solution_history - history of bestSolution status. [StepMonitor.x] energy_history - history of bestEnergy status. [StepMonitor.y] signal_handler - catches the interrupt signal. [***disabled***] """ super(AbstractEnsembleSolver, self).__init__(dim, **kwds) #self.signal_handler = None #self._handle_sigint = False # default settings for nested optimization #XXX: move nbins and npts to _InitialPoints? self._dist = None #kwds['dist'] if 'dist' in kwds else None nbins = kwds['nbins'] if 'nbins' in kwds else [1]*dim if isinstance(nbins, int): from mystic.math.grid import randomly_bin nbins = randomly_bin(nbins, dim, ones=True, exact=True) self._nbins = nbins npts = kwds['npts'] if 'npts' in kwds else 1 self._npts = npts rtol = kwds['rtol'] if 'rtol' in kwds else None self._rtol = rtol from mystic.solvers import NelderMeadSimplexSolver self._solver = NelderMeadSimplexSolver self._bestSolver = None # 'best' solver (after Solve) NP = reduce(lambda x,y:x*y, nbins) if 'nbins' in kwds else npts self._allSolvers = [None for j in range(NP)] return
def __init__(self, dim, **kwds): """ Takes one initial input: dim -- dimensionality of the problem. Additional inputs: npop -- size of the trial solution population. [default = 1] nbins -- tuple of number of bins in each dimension. [default = [1]*dim] npts -- number of solver instances. [default = 1] Important class members: nDim, nPop = dim, npop generations - an iteration counter. evaluations - an evaluation counter. bestEnergy - current best energy. bestSolution - current best parameter set. [size = dim] popEnergy - set of all trial energy solutions. [size = npop] population - set of all trial parameter solutions. [size = dim*npop] solution_history - history of bestSolution status. [StepMonitor.x] energy_history - history of bestEnergy status. [StepMonitor.y] signal_handler - catches the interrupt signal. [***disabled***] """ super(AbstractEnsembleSolver, self).__init__(dim, **kwds) #self.signal_handler = None #self._handle_sigint = False # default settings for nested optimization nbins = [1]*dim if kwds.has_key('nbins'): nbins = kwds['nbins'] if isinstance(nbins, int): from mystic.math.grid import randomly_bin nbins = randomly_bin(nbins, dim) self._nbins = nbins npts = 1 if kwds.has_key('npts'): npts = kwds['npts'] self._npts = npts from mystic.solvers import NelderMeadSimplexSolver self._solver = NelderMeadSimplexSolver self._bestSolver = None # 'best' solver (after Solve) self._total_evals = 0 # total function calls (after Solve) return
def __init__(self, dim, **kwds): """ Takes one initial input: dim -- dimensionality of the problem. Additional inputs: npop -- size of the trial solution population. [default = 1] nbins -- tuple of number of bins in each dimension. [default = [1]*dim] npts -- number of solver instances. [default = 1] Important class members: nDim, nPop = dim, npop generations - an iteration counter. evaluations - an evaluation counter. bestEnergy - current best energy. bestSolution - current best parameter set. [size = dim] popEnergy - set of all trial energy solutions. [size = npop] population - set of all trial parameter solutions. [size = dim*npop] solution_history - history of bestSolution status. [StepMonitor.x] energy_history - history of bestEnergy status. [StepMonitor.y] signal_handler - catches the interrupt signal. [***disabled***] """ super(AbstractNestedSolver, self).__init__(dim, **kwds) #self.signal_handler = None #self._handle_sigint = False # default settings for nested optimization nbins = [1] * dim if kwds.has_key('nbins'): nbins = kwds['nbins'] if isinstance(nbins, int): from mystic.math.grid import randomly_bin nbins = randomly_bin(nbins, dim) self._nbins = nbins npts = 1 if kwds.has_key('npts'): npts = kwds['npts'] self._npts = npts from mystic.solvers import NelderMeadSimplexSolver self._solver = NelderMeadSimplexSolver self._bestSolver = None # 'best' solver (after Solve) self._total_evals = 0 # total function calls (after Solve) return
def _InitialPoints(self): """Generate a grid of starting points for the ensemble of optimizers""" nbins = self._nbins if isinstance(nbins, int): from mystic.math.grid import randomly_bin nbins = randomly_bin(nbins, self.nDim, ones=True, exact=True) if len(self._strictMax): upper = list(self._strictMax) else: upper = list(self._defaultMax) if len(self._strictMin): lower = list(self._strictMin) else: lower = list(self._defaultMin) # generate arrays of points defining a grid in parameter space grid_dimensions = self.nDim bins = [] for i in range(grid_dimensions): step = abs(upper[i] - lower[i]) / nbins[i] bins.append([lower[i] + (j + 0.5) * step for j in range(nbins[i])]) # build a grid of starting points from mystic.math import gridpts return gridpts(bins, self._dist)