랜덤 시드를 42로 설정하여 난수 생성을 일관성 있게 변경

This commit is contained in:
jung-geun
2024-03-12 21:13:51 +09:00
parent ca44ff5f7a
commit 71cc5308f8
3 changed files with 16 additions and 7 deletions

View File

@@ -1,8 +1,8 @@
[![Python Package Index publish](https://github.com/jung-geun/PSO/actions/workflows/pypi.yml/badge.svg?event=push)](https://github.com/jung-geun/PSO/actions/workflows/pypi.yml) [![Python Package Index publish](https://github.com/jung-geun/PSO/actions/workflows/pypi.yml/badge.svg?event=push)](https://github.com/jung-geun/PSO/actions/workflows/pypi.yml)
[![PyPI - Version](https://img.shields.io/pypi/v/pso2keras)](https://pypi.org/project/pso2keras/) [![PyPI - Version](https://img.shields.io/pypi/v/pso2keras)](https://pypi.org/project/pso2keras/)
[![Quality Gate Status](https://sonar.pieroot.xyz/api/project_badges/measure?project=pieroot_pso_6a2f36a9-2688-4900-a4a5-5be85f36f75a&metric=alert_status&token=sqb_5fa45d924cd1c13f71a23a9283fba9460dc63eb6)](https://sonar.pieroot.xyz/dashboard?id=pieroot_pso_6a2f36a9-2688-4900-a4a5-5be85f36f75a) [![Quality Gate Status](https://sonar.pieroot.xyz/api/project_badges/measure?project=pieroot_pso_AY4yioUduAwlZ9Y7RLBU&metric=alert_status&token=sqb_48381b203cab5da421d40ebf2f09903ef90e6004)](https://sonar.pieroot.xyz/dashboard?id=pieroot_pso_AY4yioUduAwlZ9Y7RLBU)
[![Duplicated Lines (%)](https://sonar.pieroot.xyz/api/project_badges/measure?project=pieroot_pso_6a2f36a9-2688-4900-a4a5-5be85f36f75a&metric=duplicated_lines_density&token=sqb_5fa45d924cd1c13f71a23a9283fba9460dc63eb6)](https://sonar.pieroot.xyz/dashboard?id=pieroot_pso_6a2f36a9-2688-4900-a4a5-5be85f36f75a) [![Duplicated Lines (%)](https://sonar.pieroot.xyz/api/project_badges/measure?project=pieroot_pso_AY4yioUduAwlZ9Y7RLBU&metric=duplicated_lines_density&token=sqb_48381b203cab5da421d40ebf2f09903ef90e6004)](https://sonar.pieroot.xyz/dashboard?id=pieroot_pso_AY4yioUduAwlZ9Y7RLBU)
[![Security Rating](https://sonar.pieroot.xyz/api/project_badges/measure?project=pieroot_pso_6a2f36a9-2688-4900-a4a5-5be85f36f75a&metric=security_rating&token=sqb_5fa45d924cd1c13f71a23a9283fba9460dc63eb6)](https://sonar.pieroot.xyz/dashboard?id=pieroot_pso_6a2f36a9-2688-4900-a4a5-5be85f36f75a) [![Security Rating](https://sonar.pieroot.xyz/api/project_badges/measure?project=pieroot_pso_AY4yioUduAwlZ9Y7RLBU&metric=security_rating&token=sqb_48381b203cab5da421d40ebf2f09903ef90e6004)](https://sonar.pieroot.xyz/dashboard?id=pieroot_pso_AY4yioUduAwlZ9Y7RLBU)
# PSO # PSO

View File

@@ -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}"

View File

@@ -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()