mirror of
https://github.com/jung-geun/PSO.git
synced 2025-12-19 20:44:39 +09:00
랜덤 시드를 42로 설정하여 난수 생성을 일관성 있게 변경
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
[](https://github.com/jung-geun/PSO/actions/workflows/pypi.yml)
|
[](https://github.com/jung-geun/PSO/actions/workflows/pypi.yml)
|
||||||
[](https://pypi.org/project/pso2keras/)
|
[](https://pypi.org/project/pso2keras/)
|
||||||
[](https://sonar.pieroot.xyz/dashboard?id=pieroot_pso_6a2f36a9-2688-4900-a4a5-5be85f36f75a)
|
[](https://sonar.pieroot.xyz/dashboard?id=pieroot_pso_AY4yioUduAwlZ9Y7RLBU)
|
||||||
[](https://sonar.pieroot.xyz/dashboard?id=pieroot_pso_6a2f36a9-2688-4900-a4a5-5be85f36f75a)
|
[](https://sonar.pieroot.xyz/dashboard?id=pieroot_pso_AY4yioUduAwlZ9Y7RLBU)
|
||||||
[](https://sonar.pieroot.xyz/dashboard?id=pieroot_pso_6a2f36a9-2688-4900-a4a5-5be85f36f75a)
|
[](https://sonar.pieroot.xyz/dashboard?id=pieroot_pso_AY4yioUduAwlZ9Y7RLBU)
|
||||||
|
|
||||||
# PSO
|
# PSO
|
||||||
|
|
||||||
|
|||||||
@@ -530,7 +530,7 @@ class Optimizer:
|
|||||||
* (epoch % weight_reduction)
|
* (epoch % weight_reduction)
|
||||||
/ weight_reduction
|
/ weight_reduction
|
||||||
)
|
)
|
||||||
rng = np.random.default_rng()
|
rng = np.random.default_rng(seed=42)
|
||||||
for i in part_pbar:
|
for i in part_pbar:
|
||||||
part_pbar.set_description(
|
part_pbar.set_description(
|
||||||
f"loss: {min_loss:.4f} acc: {max_acc:.4f} mse: {min_mse:.4f}"
|
f"loss: {min_loss:.4f} acc: {max_acc:.4f} mse: {min_mse:.4f}"
|
||||||
|
|||||||
@@ -139,7 +139,16 @@ class Particle:
|
|||||||
|
|
||||||
def set_model(self, model: keras.Model):
|
def set_model(self, model: keras.Model):
|
||||||
self.model = model
|
self.model = model
|
||||||
self.__reset_particle()
|
|
||||||
|
def compile(self):
|
||||||
|
if self.model is None:
|
||||||
|
raise ValueError(self.MODEL_IS_NONE)
|
||||||
|
|
||||||
|
self.model.compile(
|
||||||
|
optimizer="adam",
|
||||||
|
loss=self.loss,
|
||||||
|
metrics=["accuracy", "mse"],
|
||||||
|
)
|
||||||
|
|
||||||
def get_weights(self):
|
def get_weights(self):
|
||||||
if self.model is None:
|
if self.model is None:
|
||||||
@@ -247,7 +256,7 @@ class Particle:
|
|||||||
encode_p, p_sh, p_len = self._encode(weights=self.best_weights)
|
encode_p, p_sh, p_len = self._encode(weights=self.best_weights)
|
||||||
encode_g, g_sh, g_len = self._encode(weights=Particle.g_best_weights)
|
encode_g, g_sh, g_len = self._encode(weights=Particle.g_best_weights)
|
||||||
|
|
||||||
rng = np.random.default_rng()
|
rng = np.random.default_rng(seed=42)
|
||||||
r_0 = rng.random()
|
r_0 = rng.random()
|
||||||
r_1 = rng.random()
|
r_1 = rng.random()
|
||||||
|
|
||||||
@@ -300,7 +309,7 @@ class Particle:
|
|||||||
encode_p, p_sh, p_len = self._encode(weights=self.best_weights)
|
encode_p, p_sh, p_len = self._encode(weights=self.best_weights)
|
||||||
encode_g, g_sh, g_len = self._encode(weights=Particle.g_best_weights)
|
encode_g, g_sh, g_len = self._encode(weights=Particle.g_best_weights)
|
||||||
|
|
||||||
rng = np.random.default_rng()
|
rng = np.random.default_rng(seed=42)
|
||||||
r_0 = rng.random()
|
r_0 = rng.random()
|
||||||
r_1 = rng.random()
|
r_1 = rng.random()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user