Code Duplication    Length = 22-23 lines in 3 locations

NiaPy/algorithms/modified/saba.py 1 location

@@ 116-138 (lines=23) @@
113
		})
114
		return d
115
116
	def initPopulation(self, task):
117
		r"""Initialize the starting population.
118
119
		Parameters:
120
			task (Task): Optimization task
121
122
		Returns:
123
			Tuple[numpy.ndarray, numpy.ndarray[float], Dict[str, Any]]:
124
				1. New population.
125
				2. New population fitness/function values.
126
				3. Additional arguments:
127
					* A (float): Loudness.
128
					* S (numpy.ndarray): TODO
129
					* Q (numpy.ndarray[float]): 	TODO
130
					* v (numpy.ndarray[float]): TODO
131
132
		See Also:
133
			* :func:`NiaPy.algorithms.Algorithm.initPopulation`
134
		"""
135
		Sol, Fitness, d = Algorithm.initPopulation(self, task)
136
		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)
137
		d.update({'A': A, 'S': S, 'Q': Q, 'v': v})
138
		return Sol, Fitness, d
139
140
	def localSearch(self, best, A, task, **kwargs):
141
		r"""Improve the best solution according to the Yang (2010).

NiaPy/algorithms/basic/ba.py 1 location

@@ 109-130 (lines=22) @@
106
		})
107
		return d
108
109
	def initPopulation(self, task):
110
		r"""Initialize the starting population.
111
112
		Parameters:
113
			task (Task): Optimization task
114
115
		Returns:
116
			Tuple[numpy.ndarray, numpy.ndarray[float], Dict[str, Any]]:
117
				1. New population.
118
				2. New population fitness/function values.
119
				3. Additional arguments:
120
					* S (numpy.ndarray): Solutions
121
					* Q (numpy.ndarray[float]): Frequencies
122
					* v (numpy.ndarray[float]): Velocities
123
124
		See Also:
125
			* :func:`NiaPy.algorithms.Algorithm.initPopulation`
126
		"""
127
		Sol, Fitness, d = Algorithm.initPopulation(self, task)
128
		S, Q, v = full([self.NP, task.D], 0.0), full(self.NP, 0.0), full([self.NP, task.D], 0.0)
129
		d.update({'S': S, 'Q': Q, 'v': v})
130
		return Sol, Fitness, d
131
132
	def localSearch(self, best, task, **kwargs):
133
		r"""Improve the best solution according to the Yang (2010).

NiaPy/algorithms/modified/plba.py 1 location

@@ 65-86 (lines=22) @@
62
		Algorithm.setParameters(self, NP=80, **ukwargs)
63
		self.A, self.r = 0.9, 0.1
64
65
	def initPopulation(self, task):
66
		r"""Initialize the initial population.
67
68
		Parameters:
69
			task (Task): Optimization task
70
71
		Returns:
72
			Tuple[numpy.ndarray, numpy.ndarray[float], Dict[str, Any]]:
73
				1. New population.
74
				2. New population fitness/function values.
75
				3. Additional arguments:
76
					* S (numpy.ndarray): Solutions
77
					* Q (numpy.ndarray[float]): Frequencies
78
					* v (numpy.ndarray[float]): Velocities
79
80
		See Also:
81
			* :func:`NiaPy.algorithms.Algorithm.initPopulation`
82
		"""
83
		Sol, Fitness, d = Algorithm.initPopulation(self, task)
84
		S, Q, v = full([self.NP, task.D], 0.0), full(self.NP, 0.0), full([self.NP, task.D], 0.0)
85
		d.update({'S': S, 'Q': Q, 'v': v})
86
		return Sol, Fitness, d
87
88
	def localSearch(self, best, task, **kwargs):
89
		r"""Improve the best solution according to the Yang (2010).