Skip to content

Commit e9fa65e

Browse files
committed
chore(root): Removes unnecessary comments [2/3].
1 parent fedc495 commit e9fa65e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+6
-1164
lines changed

opytimizer/optimizers/boolean/bmrfo.py

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,10 @@ def __init__(self, params: Optional[Dict[str, Any]] = None) -> None:
3838

3939
logger.info("Overriding class: Optimizer -> BMRFO.")
4040

41-
# Overrides its parent class with the receiving params
4241
super(BMRFO, self).__init__()
4342

44-
# Somersault foraging
4543
self.S = np.array([1])
4644

47-
# Builds the class
4845
self.build(params)
4946

5047
logger.info("Class overrided.")
@@ -84,23 +81,16 @@ def _cyclone_foraging(
8481
8582
"""
8683

87-
# Generates binary random numbers
8884
r1 = r.generate_binary_random_number(best_position.shape)
8985
beta = r.generate_binary_random_number(best_position.shape)
9086

91-
# Generates a uniform random number
9287
u = r.generate_uniform_random_number()
93-
94-
# Checks if current iteration proportion is smaller than random generated number
9588
if iteration / n_iterations < u:
96-
# Generates binary random positions
9789
r_position = r.generate_binary_random_number(
9890
size=(agents[i].n_variables, agents[i].n_dimensions)
9991
)
10092

101-
# Checks if the index is equal to zero
10293
if i == 0:
103-
# Calculates the cyclone foraging
10494
partial_one = np.logical_or(
10595
r1, np.logical_xor(r_position, agents[i].position)
10696
)
@@ -110,10 +100,7 @@ def _cyclone_foraging(
110100
cyclone_foraging = np.logical_and(
111101
r_position, np.logical_and(partial_one, partial_two)
112102
)
113-
114-
# If index is different than zero
115103
else:
116-
# Calculates the cyclone foraging
117104
partial_one = np.logical_or(
118105
r1, np.logical_xor(agents[i - 1].position, agents[i].position)
119106
)
@@ -123,12 +110,8 @@ def _cyclone_foraging(
123110
cyclone_foraging = np.logical_and(
124111
r_position, np.logical_and(partial_one, partial_two)
125112
)
126-
127-
# If current iteration proportion is bigger than random generated number
128113
else:
129-
# Checks if the index is equal to zero
130114
if i == 0:
131-
# Calculates the cyclone foraging
132115
partial_one = np.logical_or(
133116
r1, np.logical_xor(best_position, agents[i].position)
134117
)
@@ -138,10 +121,7 @@ def _cyclone_foraging(
138121
cyclone_foraging = np.logical_and(
139122
best_position, np.logical_and(partial_one, partial_two)
140123
)
141-
142-
# If index is different than zero
143124
else:
144-
# Calculates the cyclone foraging
145125
partial_one = np.logical_or(
146126
r1, np.logical_xor(agents[i - 1].position, agents[i].position)
147127
)
@@ -169,13 +149,10 @@ def _chain_foraging(
169149
170150
"""
171151

172-
# Generates binary random numbers
173152
r1 = r.generate_binary_random_number(best_position.shape)
174153
alpha = r.generate_binary_random_number(best_position.shape)
175154

176-
# Checks if the index is equal to zero
177155
if i == 0:
178-
# Calculates the chain foraging
179156
partial_one = np.logical_and(
180157
r1, np.logical_xor(best_position, agents[i].position)
181158
)
@@ -185,10 +162,7 @@ def _chain_foraging(
185162
chain_foraging = np.logical_or(
186163
agents[i].position, np.logical_or(partial_one, partial_two)
187164
)
188-
189-
# If index is different than zero
190165
else:
191-
# Calculates the chain foraging
192166
partial_one = np.logical_and(
193167
r1, np.logical_xor(agents[i - 1].position, agents[i].position)
194168
)
@@ -215,11 +189,9 @@ def _somersault_foraging(
215189
216190
"""
217191

218-
# Generates binary random numbers
219192
r1 = r.generate_binary_random_number(best_position.shape)
220193
r2 = r.generate_binary_random_number(best_position.shape)
221194

222-
# Calculates the somersault foraging
223195
somersault_foraging = np.logical_or(
224196
position,
225197
np.logical_and(
@@ -245,40 +217,25 @@ def update(
245217
246218
"""
247219

248-
# Iterates through all agents
249220
for i, agent in enumerate(space.agents):
250-
# Generates an uniform random number
251221
r1 = r.generate_uniform_random_number()
252-
253-
# If random number is smaller than 1/2
254222
if r1 < 0.5:
255-
# Performs the cyclone foraging
256223
agent.position = self._cyclone_foraging(
257224
space.agents, space.best_agent.position, i, iteration, n_iterations
258225
)
259-
260-
# If random number is bigger than 1/2
261226
else:
262-
# Performs the chain foraging
263227
agent.position = self._chain_foraging(
264228
space.agents, space.best_agent.position, i
265229
)
266230

267-
# Clips the agent's limits
268231
agent.clip_by_bound()
269232

270-
# Evaluates the agent
271233
agent.fit = function(agent.position)
272-
273-
# If new agent's fitness is better than best
274234
if agent.fit < space.best_agent.fit:
275-
# Replace the best agent's position and fitness with its copy
276235
space.best_agent.position = copy.deepcopy(agent.position)
277236
space.best_agent.fit = copy.deepcopy(agent.fit)
278237

279-
# Iterates through all agents
280238
for agent in space.agents:
281-
# Performs the somersault foraging
282239
agent.position = self._somersault_foraging(
283240
agent.position, space.best_agent.position
284241
)

opytimizer/optimizers/boolean/bpso.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,11 @@ def __init__(self, params: Optional[Dict[str, Any]] = None) -> None:
4040

4141
logger.info("Overriding class: Optimizer -> BPSO.")
4242

43-
# Overrides its parent class with the receiving params
4443
super(BPSO, self).__init__()
4544

46-
# Cognitive constant
4745
self.c1 = np.array([1])
48-
49-
# Social constant
5046
self.c2 = np.array([1])
5147

52-
# Builds the class
5348
self.build(params)
5449

5550
logger.info("Class overrided.")
@@ -114,7 +109,6 @@ def compile(self, space: Space) -> None:
114109
115110
"""
116111

117-
# Arrays of local positions and velocities
118112
self.local_position = np.zeros(
119113
(space.n_agents, space.n_variables, space.n_dimensions), dtype=bool
120114
)
@@ -131,22 +125,14 @@ def evaluate(self, space: Space, function: Function) -> None:
131125
132126
"""
133127

134-
# Iterates through all agents
135128
for i, agent in enumerate(space.agents):
136-
# Calculates the fitness value of current agent
137129
fit = function(agent.position)
138-
139-
# If fitness is better than agent's best fit
140130
if fit < agent.fit:
141-
# Updates its current fitness to the newer one
142131
agent.fit = fit
143132

144-
# Also updates the local best position to current's agent position
145133
self.local_position[i] = copy.deepcopy(agent.position)
146134

147-
# If agent's fitness is better than global fitness
148135
if agent.fit < space.best_agent.fit:
149-
# Makes a deep copy of agent's local best position and fitness to the best agent
150136
space.best_agent.position = copy.deepcopy(self.local_position[i])
151137
space.best_agent.fit = copy.deepcopy(agent.fit)
152138
space.best_agent.ts = int(time.time())
@@ -159,13 +145,10 @@ def update(self, space: Space) -> None:
159145
160146
"""
161147

162-
# Iterates through all agents
163148
for i, agent in enumerate(space.agents):
164-
# Defines random binary numbers
165149
r1 = r.generate_binary_random_number(agent.position.shape)
166150
r2 = r.generate_binary_random_number(agent.position.shape)
167151

168-
# Calculates the local and global partials
169152
local_partial = np.logical_and(
170153
self.c1,
171154
np.logical_xor(

opytimizer/optimizers/boolean/umda.py

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,12 @@ def __init__(self, params: Optional[Dict[str, Any]] = None) -> None:
3434
3535
"""
3636

37-
# Overrides its parent class with the receiving params
3837
super(UMDA, self).__init__()
3938

40-
# Probability of selection
4139
self.p_selection = 0.75
42-
43-
# Distribution lower bound
4440
self.lower_bound = 0.05
45-
46-
# Distribution upper bound
4741
self.upper_bound = 0.95
4842

49-
# Builds the class
5043
self.build(params)
5144

5245
logger.info("Class overrided.")
@@ -109,18 +102,12 @@ def _calculate_probability(self, agents: List[Agent]) -> np.ndarray:
109102
110103
"""
111104

112-
# Creates an empty array of probabilities
113105
probs = np.zeros((agents[0].n_variables, agents[0].n_dimensions))
114106

115-
# For every pre-selected agent
116107
for agent in agents:
117-
# Increases if feature is selected
118108
probs += agent.position
119109

120-
# Normalizes into real probabilities
121110
probs /= len(agents)
122-
123-
# Clips between pre-defined lower and upper bounds
124111
probs = np.clip(probs, self.lower_bound, self.upper_bound)
125112

126113
return probs
@@ -136,10 +123,8 @@ def _sample_position(self, probs: np.ndarray) -> np.ndarray:
136123
137124
"""
138125

139-
# Creates a uniform random array with the same shape as `probs`
140126
r1 = r.generate_uniform_random_number(size=(probs.shape[0], probs.shape[1]))
141127

142-
# Samples new positions
143128
new_position = np.where(probs < r1, True, False)
144129

145130
return new_position
@@ -151,22 +136,14 @@ def update(self, space: Space) -> None:
151136
space: Space containing agents and update-related information.
152137
153138
"""
154-
# Retrieves the number of agents
155-
n_agents = len(space.agents)
156139

157-
# Selects the individuals through ranking
140+
n_agents = len(space.agents)
158141
n_selected = int(n_agents * self.p_selection)
159142

160-
# Sorts agents
161143
space.agents.sort(key=lambda x: x.fit)
162144

163-
# Calculates the probability of ocurrence from selected agents
164145
probs = self._calculate_probability(space.agents[:n_selected])
165146

166-
# Iterates through every agents
167147
for agent in space.agents:
168-
# Samples new agent's position
169148
agent.position = self._sample_position(probs)
170-
171-
# Checks its limits
172149
agent.clip_by_bound()

0 commit comments

Comments
 (0)