예제 #1
0
파일: grnm.py 프로젝트: ustaros-ai/pyopus
	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)
예제 #2
0
	def reset(self, x0):
		"""
		Puts the optimizer in its initial state and sets the initial point to 
		be the 1-dimensional array *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 of size (*ndim*+1) times *ndim* it 
		specifies the initial simplex. 
		"""
		# Debug message
		if self.debug:
			DbgMsgOut("NM", "Resetting.")
			
		# Make it an array
		x0=array(x0)

		# Is x0 a point or a simplex?
		if x0.ndim==1:
			# Point
			# Set x now
			Optimizer.reset(self, x0)
			
			if self.debug:
				DbgMsgOut("NM", "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("NM", "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)
		
		# Reset counters
		self.nr=0
		self.ne=0
		self.noc=0
		self.nic=0
		self.ns=0

		self.nrok=0
		self.neok=0
		self.nocok=0
		self.nicok=0
		
		self.icconv=0
		self.occonv=0
예제 #3
0
파일: sdnm.py 프로젝트: xanderhsia/pyopus
	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)
예제 #4
0
파일: sdnm.py 프로젝트: ustaros-ai/pyopus
    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)