np random seed 고정
각 함수의 설명 추가
This commit is contained in:
jung-geun
2023-06-23 04:00:59 +00:00
parent 34729e9b33
commit 953cd44396
8 changed files with 244 additions and 79 deletions

19
xor.py
View File

@@ -5,11 +5,13 @@ os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
import tensorflow as tf
tf.random.set_seed(777) # for reproducibility
import numpy as np
np.random.seed(777)
# from pso_tf import PSO
from pso import Optimizer
from tensorflow import keras
import numpy as np
from tensorflow import keras
from tensorflow.keras.models import Sequential
@@ -38,20 +40,11 @@ def make_model():
# %%
model = make_model()
x_test, y_test = get_data()
# loss = 'binary_crossentropy'
# loss = 'categorical_crossentropy'
# loss = 'sparse_categorical_crossentropy'
# loss = 'kullback_leibler_divergence'
# loss = 'poisson'
# loss = 'cosine_similarity'
# loss = 'log_cosh'
# loss = 'huber_loss'
# loss = 'mean_absolute_error'
# loss = 'mean_absolute_percentage_error'
loss = 'mean_squared_error'
loss = ['mean_squared_error', 'mean_squared_logarithmic_error', 'binary_crossentropy', 'categorical_crossentropy', 'sparse_categorical_crossentropy', 'kullback_leibler_divergence', 'poisson', 'cosine_similarity', 'log_cosh', 'huber_loss', 'mean_absolute_error', 'mean_absolute_percentage_error']
pso_xor = Optimizer(model,
loss=loss, n_particles=75, c0=0.35, c1=0.8, w_min=0.6, w_max=1.2, negative_swarm=0.25)
loss=loss[0], n_particles=75, c0=0.35, c1=0.8, w_min=0.6, w_max=1.2, negative_swarm=0.25)
best_score = pso_xor.fit(
x_test, y_test, epochs=200, save=True, save_path="./result/xor", renewal="acc", empirical_balance=False, Dispersion=False, check_point=25)