Esempio n. 1
0
    def set_parameters(self,
                       n=None,
                       alpha=0.1,
                       gamma=0.3,
                       rho=-0.2,
                       sigma=-0.2,
                       **ukwargs):
        r"""Set the arguments of an algorithm.

		Arguments:
			n (Optional[int]): Number of individuals.
			alpha (Optional[float]): Reflection coefficient parameter
			gamma (Optional[float]): Expansion coefficient parameter
			rho (Optional[float]): Contraction coefficient parameter
			sigma (Optional[float]): Shrink coefficient parameter

		See Also:
			* :func:`NiaPy.algorithms.Algorithm.setParameters`
		"""
        Algorithm.set_parameters(self,
                                 n=n,
                                 init_pop_func=ukwargs.pop(
                                     'init_pop_func', self.init_pop),
                                 **ukwargs)
        self.alpha, self.gamma, self.rho, self.sigma = alpha, gamma, rho, sigma
Esempio n. 2
0
	def set_parameters(self, **ukwargs):
		r"""Set the algorithm parameters/arguments.

		Args:
			ukwargs (dict): Additional keyword arguments.
		"""
		Algorithm.set_parameters(self, **ukwargs)
Esempio n. 3
0
    def set_parameters(self,
                       M=40,
                       NoLsTests=5,
                       NoLs=5,
                       NoLsBest=5,
                       NoEnabled=17,
                       BONUS1=10,
                       BONUS2=1,
                       LSs=(MTS_LS1, MTS_LS2, MTS_LS3),
                       **ukwargs):
        r"""Set the arguments of the algorithm.

		Arguments:
			M (int): Number of individuals in population.
			NoLsTests (int): Number of test runs on local search algorithms.
			NoLs (int): Number of local search algorithm runs.
			NoLsBest (int): Number of locals search algorithm runs on best solution.
			NoEnabled (int): Number of best solution for testing.
			BONUS1 (int): Bonus for improving global best solution.
			BONUS2 (int): Bonus for improving self.
			LSs (Iterable[Callable[[numpy.ndarray, float, numpy.ndarray, float, bool, numpy.ndarray, Task, Dict[str, Any]], Tuple[numpy.ndarray, float, numpy.ndarray, float, bool, int, numpy.ndarray]]]): Local searches to use.

		See Also:
			* :func:`NiaPy.algorithms.Algorithm.setParameters`
		"""
        Algorithm.set_parameters(self, n=ukwargs.pop('n', M), **ukwargs)
        self.NoLsTests, self.NoLs, self.NoLsBest, self.NoEnabled, self.BONUS1, self.BONUS2 = NoLsTests, NoLs, NoLsBest, NoEnabled, BONUS1, BONUS2
        self.LSs = LSs
Esempio n. 4
0
    def set_parameters(self,
                       n=100,
                       a=0.5,
                       epsilon=0.001,
                       alpha=1.0,
                       r=0.5,
                       qmin=0.0,
                       qmax=2.0,
                       **ukwargs):
        r"""Set the parameters of the algorithm.

		Args:
			n (int): Number of individuals in population.
			a (Optional[float]): Starting loudness.
			epsilon (Optional[float]): Scaling factor.
			alpha (Optional[float]): Constant for updating loudness.
			r (Optional[float]): Pulse rate.
			qmin (Optional[float]): Minimum frequency.
			qmax (Optional[float]): Maximum frequency.

		See Also:
			* :func:`NiaPy.algorithms.Algorithm.setParameters`
		"""
        Algorithm.set_parameters(self, n=n, **ukwargs)
        self.A, self.epsilon, self.alpha, self.r, self.Qmin, self.Qmax = a, epsilon, alpha, r, qmin, qmax
Esempio n. 5
0
 def test_init_population_numpy_fine(self):
     r"""Test if custome generation initialization works ok."""
     a = Algorithm(n=10, init_pop_func=init_pop_numpy)
     t = Task(d=20, benchmark=Sphere())
     self.assertTrue(
         np.array_equal(np.full((10, t.D), 0.0),
                        a.init_population(t)[0]))
Esempio n. 6
0
File: de.py Progetto: kb2623/WeOptPy
    def set_parameters(self,
                       n=50,
                       F=1,
                       CR=0.8,
                       CrossMutt=cross_rand1,
                       **ukwargs):
        r"""Set the algorithm parameters.

		Args:
			n (Optional[int]): Population size.
			F (Optional[float]): Scaling factor.
			CR (Optional[float]): Crossover rate.
			CrossMutt (Optional[Callable[[numpy.ndarray, int, numpy.ndarray, float, float, mtrand.RandomState, list], numpy.ndarray]]): Crossover and mutation strategy.
			ukwargs (Dict[str, Any]): Additional arguments.

		See Also:
			* :func:`WeOptPy.algorithms.Algorithm.setParameters`
		"""
        Algorithm.set_parameters(self,
                                 n=n,
                                 init_pop_func=ukwargs.pop(
                                     'init_pop_func', default_individual_init),
                                 itype=ukwargs.pop('itype', Individual),
                                 **ukwargs)
        self.F, self.CR, self.CrossMutt = F, CR, CrossMutt
Esempio n. 7
0
    def set_parameters(self, epsilon=1e-20, **ukwargs):
        r"""Set core parameters of CovarianceMatrixAdaptionEvolutionStrategy algorithm.

		Args:
			epsilon (float): Small number.
			ukwargs (Dict[str, Any]): Additional arguments.
		"""
        Algorithm.set_parameters(self, **ukwargs)
        self.epsilon = epsilon
Esempio n. 8
0
    def set_parameters(self, delta=0.5, Neighborhood=neighborhood, **ukwargs):
        r"""Set the algorithm parameters/arguments.

		Args:
			* delta (Optional[float]): Change for searching in neighborhood.
			* Neighborhood (Optional[Callable[numpy.ndarray, float, Task], Tuple[numpy.ndarray, float]]]): Function for getting neighbours.
		"""
        Algorithm.set_parameters(self, n=1, **ukwargs)
        self.delta, self.Neighborhood = delta, Neighborhood
Esempio n. 9
0
 def test_init_population_individual_fine(self):
     r"""Test if custom generation initialization works ok."""
     a = Algorithm(n=10,
                   init_pop_func=init_pop_individual,
                   itype=Individual)
     t = Task(d=20, benchmark=Sphere())
     i = Individual(x=np.full(t.D, 0.0), task=t)
     pop, fpop, args, kwargs = a.init_population(t)
     for e in pop:
         self.assertEqual(i, e)
Esempio n. 10
0
    def set_parameters(self, n=25, a=3, Rmin=0, Rmax=2, **ukwargs):
        r"""Set the arguments of an algorithm.

		Args:
			n (Optional[int]): Number of individual in population
			a (Optional[float]): Parameter for control in :math:`r_1` value
			Rmin (Optional[float]): Minimu value for :math:`r_3` value
			Rmax (Optional[float]): Maximum value for :math:`r_3` value

		See Also:
			* :func:`NiaPy.algorithms.algorithm.Algorithm.setParameters`
		"""
        Algorithm.set_parameters(self, n=n, **ukwargs)
        self.a, self.Rmin, self.Rmax = a, Rmin, Rmax
Esempio n. 11
0
    def set_parameters(self, n=25, p=0.35, beta=1.5, **ukwargs):
        r"""Set core parameters of FlowerPollinationAlgorithm algorithm.

		Args:
			n (int): Population size.
			p (float): Probability switch.
			beta (float): Shape of the gamma distribution (should be greater than zero).

		See Also:
			* :func:`WeOptPy.algorithms.Algorithm.setParameters`
		"""
        Algorithm.set_parameters(self, n=n, **ukwargs)
        self.p, self.beta = p, beta
        self.S = np.zeros((n, 10))
Esempio n. 12
0
File: fa.py Progetto: kb2623/WeOptPy
	def set_parameters(self, n=20, alpha=1, betamin=1, gamma=2, **ukwargs):
		r"""Set the parameters of the algorithm.

		Args:
			n (Optional[int]): Population size.
			alpha (Optional[float]): Alpha parameter.
			betamin (Optional[float]): Betamin parameter.
			gamma (Optional[flaot]): Gamma parameter.
			ukwargs (Dict[str, Any]): Additional arguments.

		See Also:
			* :func:`WeOptPy.algorithms.Algorithm.setParameters`
		"""
		Algorithm.set_parameters(self, n=n, **ukwargs)
		self.alpha, self.betamin, self.gamma = alpha, betamin, gamma
Esempio n. 13
0
	def set_parameters(self, N=50, pa=0.2, alpha=0.5, **ukwargs):
		r"""Set the arguments of an algorithm.

		Arguments:
			N (int): Population size :math:`\in [1, \infty)`
			pa (float): factor :math:`\in [0, 1]`
			alpah (float): TODO
			ukwargs (Dict[str, Any]): Additional arguments

		See Also:
			* :func:`WeOptPy.algorithms.Algorithm.setParameters`
		"""
		ukwargs.pop('n', None)
		Algorithm.set_parameters(self, n=N, **ukwargs)
		self.pa, self.alpha = pa, alpha
Esempio n. 14
0
	def init_population(self, task):
		r"""Initialize first population and additional arguments.

		Args:
			task (Task): Optimization task

		Returns:
			Tuple[numpy.ndarray, numpy.ndarray, list, dict]:
				1. Initialized population
				2. Initialized population fitness/function values
				3. Additional arguments.
				4. Additional keyword arguments:
					* Xpb (numpy.ndarray): Initialized populations best positions.
					* Xpb_f (numpy.ndarray): Initialized populations best positions function/fitness values.
					* alpha (numpy.ndarray): TODO.
					* gamma (numpy.ndarray): TODO.
					* theta (numpy.ndarray): TODO.
					* rs (float): Distance of search space.

		See Also:
			* :func:`WeOptPy.algorithms.Algorithm.initPopulation`
			* :func:`WeOptPy.algorithms.AnarchicSocietyOptimization.init`
		"""
		X, X_f, args, d = Algorithm.init_population(self, task)
		alpha, gamma, theta = self.init(task)
		Xpb, Xpb_f = self.update_best_and_personal_best(X, X_f, np.full([self.NP, task.D], 0.0), np.full(self.NP, task.optType.value * np.inf))
		d.update({'Xpb': Xpb, 'Xpb_f': Xpb_f, 'alpha': alpha, 'gamma': gamma, 'theta': theta, 'rs': euclidean(task.Upper, task.Lower)})
		return X, X_f, args, d
Esempio n. 15
0
    def init_population(self, task):
        r"""Initialize starting population.

		Args:
			task (Task): Optimization task.

		Returns:
			Tuple[numpy.ndarray, numpy.ndarray, list, dict]:
				1. Initialized population.
				2. Initialized populations function/fitness value.
				3. Additional arguments:
				4. Additional keyword arguments:
					* enable (numpy.ndarray): If solution/individual is enabled.
					* improve (numpy.ndarray): If solution/individual is improved.
					* SR (numpy.ndarray): Search range.
					* grades (numpy.ndarray): Grade of solution/individual.
		"""
        X, X_f, args, d = Algorithm.init_population(self, task)
        enable, improve, SR, grades = np.full(self.NP, True), np.full(
            self.NP, True), np.full([self.NP, task.D],
                                    task.bRange / 2), np.full(self.NP, 0.0)
        d.update({
            'enable': enable,
            'improve': improve,
            'SR': SR,
            'grades': grades
        })
        return X, X_f, args, d
Esempio n. 16
0
	def type_parameters():
		r"""Get dictionary with functions for checking values of parameters.

		Returns:
			Dict[str, Callable[[Union[list, dict]], bool]]:
				* alpha (Callable[[Union[float, int]], bool]): TODO.
				* gamma (Callable[[Union[float, int]], bool]): TODO.
				* theta (Callable[[Union[float, int]], bool]): TODO.
				* nl (Callable[[Union[float, int]], bool]): TODO.
				* F (Callable[[Union[float, int]], bool]): TODO.
				* CR (Callable[[Union[float, int]], bool]): TODO.

		See Also:
			* :func:`WeOptPy.algorithms.Algorithm.typeParameters`
		"""
		d = Algorithm.type_parameters()
		d.update({
			'alpha': lambda x: True,
			'gamma': lambda x: True,
			'theta': lambda x: True,
			'nl': lambda x: True,
			'F': lambda x: isinstance(x, (int, float)) and x > 0,
			'CR': lambda x: isinstance(x, float) and 0 <= x <= 1
		})
		return d
Esempio n. 17
0
    def init_population(self, task):
        r"""Initialize the starting population.

		Parameters:
			task (Task): Optimization task

		Returns:
			Tuple[numpy.ndarray, numpy.ndarray, list, dict]:
				1. New population.
				2. New population fitness/function values.
				3. Additional arguments.
				4. Additional keyword arguments:
					* a (float): Loudness.
					* S (numpy.ndarray): TODO
					* Q (numpy.ndarray): 	TODO
					* v (numpy.ndarray): TODO

		See Also:
			* :func:`WeOptPy.algorithms.Algorithm.initPopulation`
		"""
        sol, fitness, args, d = Algorithm.init_population(self, task)
        a, s, Q, v = np.full(self.NP,
                             self.A), np.full([self.NP, task.D], 0.0), np.full(
                                 self.NP, 0.0), np.full([self.NP, task.D], 0.0)
        d.update({'a': a, 'S': s, 'Q': Q, 'v': v})
        return sol, fitness, args, d
Esempio n. 18
0
    def init_population(self, task):
        r"""Initialize the starting population.

		Parameters:
			task (Task): Optimization task

		Returns:
			Tuple[numpy.ndarray, numpy.ndarray[float], Dict[str, Any]]:
				1. New population.
				2. New population fitness/function values.
				3. Additional arguments.
				4. Additional keyword arguments:
					* S (numpy.ndarray): TODO
					* Q (numpy.ndarray): 	TODO
					* v (numpy.ndarray): TODO

		See Also:
			* :func:`WeOptPy.algorithms.Algorithm.initPopulation`
		"""
        Sol, Fitness, args, d = Algorithm.init_population(self, task)
        S, Q, v = np.full([self.NP, task.D],
                          0.0), np.full(self.NP,
                                        0.0), np.full([self.NP, task.D], 0.0)
        d.update({'S': S, 'Q': Q, 'v': v})
        return Sol, Fitness, args, d
Esempio n. 19
0
    def set_parameters(self, n=10, limit=100, **ukwargs):
        r"""Set the parameters of Artificial Bee Colony Algorithm.

		Args:
			n (int): Number of individuals in population.
			limit (Optional[Union[float, numpy.ndarray[float]]]): Limit.
			ukwargs (dict): Additional arguments.

		See Also:
			* :func:`WeOptPy.algorithms.Algorithm.setParameters`
		"""
        Algorithm.set_parameters(self,
                                 n=n,
                                 init_pop_func=default_individual_init,
                                 itype=SolutionABC,
                                 **ukwargs)
        self.FoodNumber, self.Limit = int(self.NP / 2), limit
Esempio n. 20
0
    def get_parameters(self):
        r"""Get parameters of the algorithm.

		Returns:
			Dict[str, Any]:
				* Parameter name: Represents a parameter name
				* Value of parameter: Represents the value of the parameter
		"""
        d = Algorithm.get_parameters(self)
        d.update({'delta': self.delta, 'Neighborhood': self.Neighborhood})
        return d
Esempio n. 21
0
    def set_parameters(self,
                       n=40,
                       A=0.5,
                       r=0.5,
                       Qmin=0.0,
                       Qmax=2.0,
                       **ukwargs):
        r"""Set the parameters of the algorithm.

		Args:
			A (Optional[float]): Loudness.
			r (Optional[float]): Pulse rate.
			Qmin (Optional[float]): Minimum frequency.
			Qmax (Optional[float]): Maximum frequency.

		See Also:
			* :func:`WeOptPy.algorithms.Algorithm.setParameters`
		"""
        Algorithm.set_parameters(self, n=n, **ukwargs)
        self.A, self.r, self.Qmin, self.Qmax = A, r, Qmin, Qmax
Esempio n. 22
0
    def get_parameters(self):
        r"""Get algorithm parameters values.

		Returns:
			Dict[str, Any]: TODO.

		See Also:
			* :func:`NiaPy.algorithms.algorithm.Algorithm.getParameters`
		"""
        d = Algorithm.get_parameters(self)
        d.update({'a': self.a, 'Rmin': self.Rmin, 'Rmax': self.Rmax})
        return d
Esempio n. 23
0
File: de.py Progetto: kb2623/WeOptPy
    def get_parameters(self):
        r"""Get parameters values of the algorithm.

		Returns:
			Dict[str, Any]: TODO

		See Also:
			* :func:`WeOptPy.algorithms.interfaces.Algorithm.getParameters`
		"""
        d = Algorithm.get_parameters(self)
        d.update({'F': self.F, 'CR': self.CR, 'CrossMutt': self.CrossMutt})
        return d
Esempio n. 24
0
File: sa.py Progetto: kb2623/WeOptPy
    def set_parameters(self,
                       delta=0.5,
                       T=2000,
                       deltaT=0.8,
                       coolingMethod=coolDelta,
                       epsilon=1e-23,
                       **ukwargs):
        r"""Set the algorithm parameters/arguments.

		Arguments:
			delta (Optional[float]): Movement for neighbour search.
			T (Optional[float]); Starting temperature.
			deltaT (Optional[float]): Change in temperature.
			coolingMethod (Optional[Callable]): Neighbourhood function.
			epsilon (Optional[float]): Error value.

		See Also
			* :func:`NiaPy.algorithms.Algorithm.setParameters`
		"""
        ukwargs.pop('n', None)
        Algorithm.set_parameters(self, n=1, **ukwargs)
        self.delta, self.T, self.deltaT, self.cool, self.epsilon = delta, T, deltaT, coolingMethod, epsilon
Esempio n. 25
0
    def type_parameters():
        r"""Return functions for checking values of parameters.

		Returns:
			Dict[str, Callable]:
				* Limit (Callable[Union[float, numpy.ndarray[float]]]): TODO

		See Also:
			* :func:`WeOptPy.algorithms.Algorithm.typeParameters`
		"""
        d = Algorithm.type_parameters()
        d.update({'Limit': lambda x: isinstance(x, int) and x > 0})
        return d
Esempio n. 26
0
    def get_parameters(self):
        r"""Get parameters of the algorithm.

		Returns:
			Dict[str, Any]
		"""
        d = Algorithm.get_parameters(self)
        d.update({
            'a': self.A,
            'r': self.r,
            'Qmin': self.Qmin,
            'Qmax': self.Qmax
        })
        return d
Esempio n. 27
0
    def set_parameters(self,
                       mu=1,
                       k=10,
                       c_a=1.1,
                       c_r=0.5,
                       epsilon=1e-20,
                       **ukwargs):
        r"""Set the arguments of an algorithm.

		Args:
			mu (Optional[int]): Number of parents
			k (Optional[int]): Number of iterations before checking and fixing rho
			c_a (Optional[float]): Search range amplification factor
			c_r (Optional[float]): Search range reduction factor

		See Also:
			* :func:`WeOptPy.algorithms.Algorithm.setParameters`
		"""
        Algorithm.set_parameters(self,
                                 n=mu,
                                 itype=ukwargs.pop('itype', IndividualES),
                                 **ukwargs)
        self.mu, self.k, self.c_a, self.c_r, self.epsilon = mu, k, c_a, c_r, epsilon
Esempio n. 28
0
    def init_population(self, task):
        r"""Initialize the individuals.

		Args:
			task (Task): Optimization task

		Returns:
			Tuple[numpy.ndarray, numpy.ndarray, list, dict]:
				1. Initialized population of individuals
				2. Function/fitness values for individuals
				3. Additional arguments
				4. Additional keyword arguments
		"""
        return Algorithm.init_population(self, task)
Esempio n. 29
0
	def set_parameters(self, n=43, alpha=(1, 0.83), gamma=(1.17, 0.56), theta=(0.932, 0.832), d=euclidean, dn=euclidean, nl=1, F=1.2, CR=0.25, Combination=elitism, **ukwargs):
		r"""Set the parameters for the algorithm.

		Args:
			n (int): Number of individuals in population.
			alpha (Optional[List[float]]): Factor for fickleness index function :math:`\in [0, 1]`.
			gamma (Optional[List[float]]): Factor for external irregularity index function :math:`\in [0, \infty)`.
			theta (Optional[List[float]]): Factor for internal irregularity index function :math:`\in [0, \infty)`.
			d (Optional[Callable[[float, float], float]]): function that takes two arguments that are function values and calcs the distance between them.
			dn (Optional[Callable[[numpy.ndarray, numpy.ndarray], float]]]): function that takes two arguments that are points in function landscape and calcs the distance between them.
			nl (Optional[float]): Normalized range for neighborhood search :math:`\in (0, 1]`.
			F (Optional[float]): Mutation parameter.
			CR (Optional[float]): Crossover parameter :math:`\in [0, 1]`.
			Combination (Optional[Callable[[numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, float, float, float, float, float, float, Task, mtrand.RandomState], Tuple[numpy.ndarray, float]]]): Function for combining individuals to get new position/individual.

		See Also:
			* :func:`WeOptPy.algorithms.Algorithm.setParameters`
			* Combination methods:
				* :func:`WeOptPy.algorithms.other.Elitism`
				* :func:`WeOptPy.algorithms.other.Crossover`
				* :func:`WeOptPy.algorithms.other.Sequential`
		"""
		Algorithm.set_parameters(self, n=n, **ukwargs)
		self.alpha, self.gamma, self.theta, self.d, self.dn, self.nl, self.F, self.CR, self.Combination = alpha, gamma, theta, d, dn, nl, F, CR, Combination
Esempio n. 30
0
    def get_parameters(self):
        r"""Get parameters of the algorithm.

		Returns:
			Dict[str, Any]:
				* Parameter name: Represents a parameter name
				* Value of parameter: Represents the value of the parameter
		"""
        d = Algorithm.get_parameters(self)
        d.update({
            'alpha': self.alpha,
            'gamma': self.gamma,
            'rho': self.rho,
            'sigma': self.sigma
        })
        return d