mirror of
https://github.com/jung-geun/PSO.git
synced 2025-12-19 20:44:39 +09:00
23-07-06
code space용 설정 파일 추가 mutation 설정 - 특정 확률로 파티클의 위치를 랜덤하게 방향 조정
This commit is contained in:
@@ -90,7 +90,7 @@ class Optimizer:
|
||||
negative_count += 1
|
||||
|
||||
print(f"negative swarm : {negative_count} / {self.n_particles}")
|
||||
print(f"mutation swarm : {mutation_swarm*100/self.n_particles} / {self.n_particles}")
|
||||
print(f"mutation swarm : {mutation_swarm * self.n_particles} / {self.n_particles}")
|
||||
|
||||
gc.collect()
|
||||
|
||||
|
||||
@@ -150,9 +150,11 @@ class Particle:
|
||||
+ local_rate * r0 * (encode_p - encode_w)
|
||||
+ global_rate * r1 * (encode_g - encode_w)
|
||||
)
|
||||
if np.random.rand() < self.mutation:
|
||||
|
||||
new_v += 0.5 * encode_v
|
||||
if np.random.rand() < self.mutation:
|
||||
m_v = np.random.uniform(-0.1, 0.1, len(encode_v))
|
||||
new_v = m_v
|
||||
|
||||
self.velocities = self._decode(new_v, w_sh, w_len)
|
||||
|
||||
del encode_w, w_sh, w_len
|
||||
@@ -193,8 +195,11 @@ class Particle:
|
||||
+ local_rate * r0 * (w_p * encode_p - encode_w)
|
||||
+ global_rate * r1 * (w_g * encode_g - encode_w)
|
||||
)
|
||||
if self.mutation:
|
||||
new_v += 0.5 * encode_v
|
||||
|
||||
if np.random.rand() < self.mutation:
|
||||
m_v = np.random.uniform(-0.1, 0.1, len(encode_v))
|
||||
new_v = m_v
|
||||
|
||||
self.velocities = self._decode(new_v, w_sh, w_len)
|
||||
|
||||
del encode_w, w_sh, w_len
|
||||
|
||||
Reference in New Issue
Block a user