Skip to content

Commit

Permalink
Update pypop7/optimizers/pso/ccpso2.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Evolutionary-Intelligence committed May 13, 2024
1 parent 1541be2 commit 7f26d5c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pypop7/optimizers/pso/ccpso2.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import numpy as np
import numpy as np # engine for numerical computing
from scipy.stats import cauchy

from pypop7.optimizers.core.optimizer import Optimizer
from pypop7.optimizers.pso.pso import PSO
from pypop7.optimizers.pso.pso import PSO # abstract class of all particle swarm optimizer (PSO) classes


class CCPSO2(PSO):
Expand Down Expand Up @@ -133,7 +133,7 @@ def iterate(self, x=None, y=None, p_x=None, p_y=None, n_x=None, args=None, fitne
if self._check_terminations():
return x, y, p_x, p_y, n_x
cv = np.copy(self.best_so_far_x) # context vector
indices = self._indices[np.arange(j*self._s, (j + 1)*self._s)]
indices = self._indices[np.arange(j*self._s, min(self.ndim_problem, (j + 1)*self._s))]
cv[indices] = x[i, indices]
y[j, i] = self._evaluate_fitness(cv, args)
if self.saving_fitness:
Expand All @@ -145,19 +145,19 @@ def iterate(self, x=None, y=None, p_x=None, p_y=None, n_x=None, args=None, fitne
if self._check_terminations():
return x, y, p_x, p_y, n_x
cv = np.copy(self.best_so_far_x) # context vector
indices = self._indices[np.arange(j*self._s, (j + 1)*self._s)]
indices = self._indices[np.arange(j*self._s, min(self.ndim_problem, (j + 1)*self._s))]
cv[indices] = x[i, indices]
y[j, i] = self._evaluate_fitness(cv, args)
if y[j, i] < p_y[j, i]:
p_x[i, indices], p_y[j, i] = cv[indices], y[j, i]
if y[j, i] < self._best_so_far_y:
self._improved, self._best_so_far_y = True, y[j, i]
for i in range(self.n_individuals):
indices = self._indices[np.arange(j*self._s, (j + 1)*self._s)]
indices = self._indices[np.arange(j*self._s, min(self.ndim_problem, (j + 1)*self._s))]
n_x[i, indices] = self._ring_topology(p_x, p_y, j, i, indices)
for j in range(self._k): # for each swarm
for i in range(self.n_individuals): # for each individual
indices = self._indices[np.arange(j*self._s, (j + 1)*self._s)]
indices = self._indices[np.arange(j*self._s, min(self.ndim_problem, (j + 1)*self._s))]
std = np.abs(p_x[i, indices] - n_x[i, indices])
for jj, ii in enumerate(indices):
if self.rng_optimization.random() <= self.p: # sampling from Cauchy distribution
Expand Down

0 comments on commit 7f26d5c

Please sign in to comment.