def __init__(self, function, debug=0, fstop=None, maxiter=None, reflect=1.0, expand=1.2, outerContract=0.5, innerContract=-0.5, shrink=0.25, reltol=1e-15, ftol=1e-15, xtol=1e-9, simplex=None, lam=2.0, Lam=2.0**52, psi=1e-6, tau_r=2.0**(-52), tau_a=1e-100, originalGrid=False, gridRestrainInitial=False): NelderMead.__init__(self, function, debug, fstop, maxiter, reflect, expand, outerContract, innerContract, shrink, reltol, ftol, xtol, simplex) # Simplex self.simplex=None # Grid origin and scaling self.z=None self.Delta=None # Side length bounds wrt. grid self.lam=lam self.Lam=Lam # Simplex shape lower bound self.psi=1e-6 # Grid continuity bound (relative and absolute) self.tau_r=tau_r self.tau_a=tau_a # Create initial grid with the procedure described in the paper self.originalGrid=originalGrid # Grid restrain initial simplex self.gridRestrainInitial=gridRestrainInitial
def __init__(self, function, debug=0, fstop=None, maxiter=None, reflect=1.0, expand=1.2, outerContract=0.5, innerContract=-0.5, shrink=0.25, reltol=1e-15, ftol=1e-15, xtol=1e-9, simplex=None, lam=2.0, Lam=2.0**52, c=1e-6, tau_r=2.0**(-52), tau_a=1e-100): NelderMead.__init__(self, function, debug, fstop, maxiter, reflect, expand, outerContract, innerContract, shrink, reltol, ftol, xtol, simplex) # Simplex self.simplex=None # Side vector determinant self.logDet=None # Grid origin and scaling self.z=None self.Delta=None # Side length bounds wrt. grid self.lam=lam self.Lam=Lam # Simplex shape lower bound self.c=c # Grid continuity bound (relative and absolute) self.tau_r=tau_r self.tau_a=tau_a
def __init__(self, function, debug=0, fstop=None, maxiter=None, reflect=1.0, expand=2.0, outerContract=0.5, innerContract=-0.5, shrink=0.5, reltol=1e-15, ftol=1e-15, xtol=1e-9, simplex=None, kappa=4.0, K0=1e3, N0=100.0, nu=4.5, tau=1e-18): NelderMead.__init__(self, function, debug, fstop, maxiter, reflect, expand, outerContract, innerContract, shrink, reltol, ftol, xtol, simplex) # Simplex self.simplex=None self.simplexf=None self.simpelxmoves=None # log(n! det([v])) where [v] are the n side vectors # arranged as columns of a matrix self.logDet=None # Algorithm parameters self.kappa=kappa self.K0=K0 self.N0=N0 self.nu=nu self.tau=tau # Dependent parameters self.N=None self.h=None self.epsilon=None
def check(self): """ Checks the optimization algorithm's settings and raises an exception if something is wrong. """ NelderMead.check(self) if self.lam <= 0: raise Exception, DbgMsg("SANMOPT", "lambda should be positive.") if self.Lam <= 0: raise Exception, DbgMsg("SANMOPT", "Lambda should be positive.") if self.lam > self.Lam: raise Exception, DbgMsg( "SANMOPT", "Lambda should be greater or equal lambda.") if self.c < 0: raise Exception, DbgMsg("SANMOPT", "c should be greater or equal zero.") if self.tau_r < 0 or self.tau_a < 0: raise Exception, DbgMsg( "SANMOPT", "Relative and absolute grid continuity bounds should be positive." )
def reset(self, x0): """ Puts the optimizer in its initial state and sets the initial point to be the 1-dimensional array or list *x0*. The length of the array becomes the dimension of the optimization problem (:attr:`ndim` member). The initial simplex is built around *x0* by calling the :meth:`buildSimplex` method with default values for the *rel* and *abs* arguments. If *x0* is a 2-dimensional array or list of size (*ndim*+1) times *ndim* it specifies the initial simplex. A corresponding grid is created by calling the :meth:`buildGrid` method. The initial value of the natural logarithm of the simplex side vectors determinant is calculated and stored. """ # Debug message if self.debug: DbgMsgOut("GRNMOPT", "Resetting.") # Make it an array x0=array(x0) # Is x0 a point or a simplex? if x0.ndim==1: # Point # Set x now NelderMead.reset(self, x0) if self.debug: DbgMsgOut("GRNMOPT", "Generating initial simplex from initial point.") sim=self.buildSimplex(x0) self._setSimplex(sim) self.delta=self.buildGrid() self.z=x0 else: # Simplex or error (handled in _setSimplex()) self._setSimplex(x0) self.delta=self.buildGrid() self.z=x0[0,:] if self.debug: DbgMsgOut("GRNMOPT", "Using specified initial simplex.") # Set x to first point in simplex after it was checked in _setSimplex() Optimizer.reset(self, x0[0,:]) # Reset point moves counter self.simplexmoves=zeros(self.ndim+1) # Make x tolerance an array self.xtol=array(self.xtol)
def check(self): """ Checks the optimization algorithm's settings and raises an exception if something is wrong. """ NelderMead.check(self) if self.K0<=0: raise Exception, DbgMsg("SDNMOPT", "K0 should be positive.") if self.N0<=0: raise Exception, DbgMsg("SDNMOPT", "N0 should be positive.") if self.nu<=1: raise Exception, DbgMsg("SDNMOPT", "nu should be greater than 1.") if self.tau<=0: raise Exception, DbgMsg("SDNMOPT", "tau should be positive.")
def check(self): """ Checks the optimization algorithm's settings and raises an exception if something is wrong. """ NelderMead.check(self) if self.K0 <= 0: raise Exception, DbgMsg("SDNMOPT", "K0 should be positive.") if self.N0 <= 0: raise Exception, DbgMsg("SDNMOPT", "N0 should be positive.") if self.nu <= 1: raise Exception, DbgMsg("SDNMOPT", "nu should be greater than 1.") if self.tau <= 0: raise Exception, DbgMsg("SDNMOPT", "tau should be positive.")
def __init__(self, function, debug=0, fstop=None, maxiter=None, reflect=1.0, expand=1.2, outerContract=0.5, innerContract=-0.5, shrink=0.25, reltol=1e-15, ftol=1e-15, xtol=1e-9, simplex=None, lam=2.0, Lam=2.0**52, c=1e-6, tau_r=2.0**(-52), tau_a=1e-100): NelderMead.__init__(self, function, debug, fstop, maxiter, reflect, expand, outerContract, innerContract, shrink, reltol, ftol, xtol, simplex) # Simplex self.simplex = None # Side vector determinant self.logDet = None # Grid origin and scaling self.z = None self.Delta = None # Side length bounds wrt. grid self.lam = lam self.Lam = Lam # Simplex shape lower bound self.c = c # Grid continuity bound (relative and absolute) self.tau_r = tau_r self.tau_a = tau_a
def __init__(self, function, debug=0, fstop=None, maxiter=None, reflect=1.0, expand=2.0, outerContract=0.5, innerContract=-0.5, shrink=0.5, reltol=1e-15, ftol=1e-15, xtol=1e-9, simplex=None, kappa=4.0, K0=1e3, N0=100.0, nu=4.5, tau=1e-18): NelderMead.__init__(self, function, debug, fstop, maxiter, reflect, expand, outerContract, innerContract, shrink, reltol, ftol, xtol, simplex) # Simplex self.simplex = None self.simplexf = None self.simpelxmoves = None # log(n! det([v])) where [v] are the n side vectors # arranged as columns of a matrix self.logDet = None # Algorithm parameters self.kappa = kappa self.K0 = K0 self.N0 = N0 self.nu = nu self.tau = tau # Dependent parameters self.N = None self.h = None self.epsilon = None
def check(self): """ Checks the optimization algorithm's settings and raises an exception if something is wrong. """ NelderMead.check(self) if self.lam<=0: raise Exception, DbgMsg("SANMOPT", "lambda should be positive.") if self.Lam<=0: raise Exception, DbgMsg("SANMOPT", "Lambda should be positive.") if self.lam>self.Lam: raise Exception, DbgMsg("SANMOPT", "Lambda should be greater or equal lambda.") if self.c<0: raise Exception, DbgMsg("SANMOPT", "c should be greater or equal zero.") if self.tau_r<0 or self.tau_a<0: raise Exception, DbgMsg("SANMOPT", "Relative and absolute grid continuity bounds should be positive.")
def reset(self, x0): """ Puts the optimizer in its initial state and sets the initial point to be the 1-dimensional array or list *x0*. The length of the array becomes the dimension of the optimization problem (:attr:`ndim` member). The initial simplex is built around *x0* by calling the :meth:`buildSimplex` method with default values for the *rel* and *abs* arguments. If *x0* is a 2-dimensional array or list of size (*ndim*+1) times *ndim* it specifies the initial simplex. The initial value of the natural logarithm of the simplex side vectors determinant is calculated and stored. This value gets updated at every simplex algorithm step. The only time it needs to be reevaluated is at reshape. But that is also quite simple because the reshaped simplex is orthogonal. The only place where a full determinant needs to be calculated is here. """ # Debug message if self.debug: DbgMsgOut("SDNMOPT", "Resetting.") # Make it an array x0=array(x0) # Is x0 a point or a simplex? if x0.ndim==1: # Point # Set x now NelderMead.reset(self, x0) if self.debug: DbgMsgOut("SDNMOPT", "Generating initial simplex from initial point.") sim=self.buildSimplex(x0) self._setSimplex(sim) else: # Simplex or error (handled in _setSimplex()) self._setSimplex(x0) if self.debug: DbgMsgOut("SDNMOPT", "Using specified initial simplex.") # Set x to first point in simplex after it was checked in _setSimplex() Optimizer.reset(self, x0[0,:]) # Reset point moves counter self.simplexmoves=zeros(self.ndim+1) # Calculate log(n! det([v])) where [v] are the n side vectors # arranged as columns of a matrix (v, l)=self.sortedSideVectors() self.logDet=log(abs(det(v))) # Initial h self.h=1.0 # Make x tolerance an array self.xtol=array(self.xtol)
def reset(self, x0): """ Puts the optimizer in its initial state and sets the initial point to be the 1-dimensional array or list *x0*. The length of the array becomes the dimension of the optimization problem (:attr:`ndim` member). The initial simplex is built around *x0* by calling the :meth:`buildSimplex` method with default values for the *rel* and *abs* arguments. If *x0* is a 2-dimensional array or list of size (*ndim*+1) times *ndim* it specifies the initial simplex. The initial value of the natural logarithm of the simplex side vectors determinant is calculated and stored. This value gets updated at every simplex algorithm step. The only time it needs to be reevaluated is at reshape. But that is also quite simple because the reshaped simplex is orthogonal. The only place where a full determinant needs to be calculated is here. """ # Debug message if self.debug: DbgMsgOut("SDNMOPT", "Resetting.") # Make it an array x0 = array(x0) # Is x0 a point or a simplex? if x0.ndim == 1: # Point # Set x now NelderMead.reset(self, x0) if self.debug: DbgMsgOut("SDNMOPT", "Generating initial simplex from initial point.") sim = self.buildSimplex(x0) self._setSimplex(sim) else: # Simplex or error (handled in _setSimplex()) self._setSimplex(x0) if self.debug: DbgMsgOut("SDNMOPT", "Using specified initial simplex.") # Set x to first point in simplex after it was checked in _setSimplex() Optimizer.reset(self, x0[0, :]) # Reset point moves counter self.simplexmoves = zeros(self.ndim + 1) # Calculate log(n! det([v])) where [v] are the n side vectors # arranged as columns of a matrix (v, l) = self.sortedSideVectors() self.logDet = log(abs(det(v))) # Initial h self.h = 1.0 # Make x tolerance an array self.xtol = array(self.xtol)