momentum (관성) -> momentun (돌연변이)로 수정
This commit is contained in:
jung-geun
2023-06-29 22:22:03 +09:00
parent 544a818940
commit 97abf75149
3 changed files with 17 additions and 9 deletions

View File

@@ -10,7 +10,7 @@ class Particle:
"""
Particle Swarm Optimization의 Particle을 구현한 클래스
"""
def __init__(self, model: keras.models, loss, negative: bool = False, momentun: bool = False):
def __init__(self, model: keras.models, loss, negative: bool = False, mutation: bool = False):
"""
Args:
model (keras.models): 학습 및 검증을 위한 모델
@@ -24,7 +24,7 @@ class Particle:
i_w_ = np.random.rand(len(i_w_)) / 2 - 0.25
self.velocities = self._decode(i_w_, s_, l_)
self.negative = negative
self.momentun = momentun
self.mutation = mutation
self.best_score = 0
self.best_weights = init_weights
@@ -150,7 +150,7 @@ class Particle:
+ local_rate * r0 * (encode_p - encode_w)
+ global_rate * r1 * (encode_g - encode_w)
)
if self.momentun:
if self.mutation:
new_v += 0.5 * encode_v
self.velocities = self._decode(new_v, w_sh, w_len)
del encode_w, w_sh, w_len
@@ -190,7 +190,7 @@ class Particle:
+ local_rate * r0 * (w_p * encode_p - encode_w)
+ global_rate * r1 * (w_g * encode_g - encode_w)
)
if self.momentun:
if self.mutation:
new_v += 0.5 * encode_v
self.velocities = self._decode(new_v, w_sh, w_len)
del encode_w, w_sh, w_len