Exemple #1
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
Exemple #2
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]))
Exemple #3
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
Exemple #4
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
Exemple #5
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
Exemple #6
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)
Exemple #7
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)
Exemple #8
0
    def init_population(self, task):
        r"""Initialize the initial population.

		Args:
			task (Task): Optimization task.

		Returns:
			Tuple[numpy.ndarray, numpy.ndarray, list, dict]:
				1. Initial population.
				2. Initials population fitness/utility function values.
				3. Additional arguments.
				4. Additional keyword arguments.
		"""
        pop, fpop, args, d = Algorithm.init_population(self, task)
        d.update({'S': np.zeros((self.NP, task.D))})
        return pop, fpop, args, d
Exemple #9
0
	def init_population(self, task):
		r"""Initialize the starting population.

		Args:
			task (Task): Optimization task

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

		See Also:
			* :func:`WeOptPy.algorithms.Algorithm.initPopulation`
		"""
		Fireflies, Intensity, args, _ = Algorithm.init_population(self, task)
		return Fireflies, Intensity, args, {'alpha': self.alpha}
Exemple #10
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 populaiton.
				2. Initialized populations function/fitness values.
				3. Additional arguments.
				4. Additional keyword arguments:
					* ki (int): Number of successful mutations.

		See Also:
			* :func:`WeOptPy.algorithms.Algorithm.initPopulation`
		"""
        c, fc, args, d = Algorithm.init_population(self, task)
        d.update({'ki': 0})
        return c, fc, args, d
Exemple #11
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 fitness/function values.
				3. Additional arguments:
				4. Additional keyword arguments:
					* pa_v (float): TODO

		See Also:
			* :func:`WeOptPy.algorithms.Algorithm.initPopulation`
		"""
		N, N_f, args, d = Algorithm.init_population(self, task)
		d.update({'pa_v': self.NP * self.pa})
		return N, N_f, args, d
Exemple #12
0
    def init_population(self, task):
        r"""Initialize the starting population.

		Args:
			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:
					* Probes (numpy.ndarray): TODO
					* Trial (numpy.ndarray): TODO

		See Also:
			* :func:`WeOptPy.algorithms.Algorithm.initPopulation`
		"""
        foods, fpop, args, _ = Algorithm.init_population(self, task)
        probs, trial = np.full(self.FoodNumber,
                               0.0), np.full(self.FoodNumber, 0.0)
        return foods, fpop, args, {'probs': probs, 'trial': trial}