Skip to content
Snippets Groups Projects
Commit d56c2b1d authored by Jan Habscheid's avatar Jan Habscheid
Browse files

TunerPINN, high Q makes problems

parent 2c31b6bc
Branches
Tags
1 merge request!10Clean up
Showing
with 7359 additions and 7507 deletions
This diff is collapsed.
......@@ -8,6 +8,9 @@ import os
from PINN import *
from FEniCSx import solve_heatequation_dimensionless
from ANN import load_data, prepare_data # for validation
from sklearn.metrics import root_mean_squared_error
import skopt
from skopt import gp_minimize # Import the skopt library for hyperparameter optimization
......@@ -27,7 +30,7 @@ beta = delta_T / T_ICE_lb # β
# Setup
####################################################################################################
# HPO setting
n_calls = 20
n_calls = 15 #!20
# Create solution folder for each iteration
for i in range(n_calls):
if not os.path.exists(f'models/PINN/TunerRuns/{i}'):
......@@ -43,7 +46,7 @@ num_test = 2_000
optimizer = 'adam'
display_every = 1_000
iterations = [3_000, 1_000]#![4_000, 4_000, 4_000]
iterations = [3_000, 2_000]#![4_000, 4_000, 4_000]
learning_rate = [1e-3, 1e-4]#![1e-3, 1e-4, 1e-5]
# dim_num_dense_layers = Integer(low=1, high=9, name='num_dense_layers')
......@@ -67,6 +70,23 @@ default_parameters = [
]
####################################################################################################
# Validation data
####################################################################################################
data = load_data()
data = prepare_data(data)
time_vec = data['time_validate']
Theta = data['Theta_ICE_validate']
x_right = np.array([1.0])
X, T_grid = np.meshgrid(x_right, time_vec)
X_flat = X.flatten()
T_flat = T_grid.flatten()
samples = Theta.shape[0]
X_input_PINN = []
for i in range(samples):
Q_flat = np.full_like(X_flat, Theta[i], dtype=float)
X_input_PINN = np.vstack((X_flat, Q_flat, T_flat)).T
X_input_PINN = np.array(X_input_PINN)
####################################################################################################
# Hyperparameter Optimization
......@@ -103,9 +123,9 @@ def fitness(num_dense_layers, num_dense_nodes, activation):
# Plotting
# Plot the Loss History
# dde.utils.plot_loss_history(losshistory)
# plt.savefig(f'models/PINN/TunerRuns/{ITERATION}//PINNTunerLossHistory.png')
# plt.savefig(f'models/PINN/TunerRuns/{ITERATION}//PINNTunerLossHistory.pdf')
dde.utils.plot_loss_history(losshistory)
plt.savefig(f'models/PINN/TunerRuns/{ITERATION}//PINNTunerLossHistory.png')
plt.savefig(f'models/PINN/TunerRuns/{ITERATION}//PINNTunerLossHistory.pdf')
# Plot loss divided into components
plot_loss_divided(losshistory, savefig=f'models/PINN/TunerRuns/{ITERATION}/PINNTunerLossHistory_splitted.pdf', show=False)
......@@ -139,7 +159,11 @@ def fitness(num_dense_layers, num_dense_nodes, activation):
plt.legend()
plt.savefig(f'models/PINN/TunerRuns/{ITERATION}/HeatFluxRight.pdf')
error = np.array(losshistory.loss_train).sum(axis=1).ravel().min()
# Validation for heat flux
q_predict_PINN = np.array([heat_flux_right(model, Theta[i], time_vec) for i in range(samples)]).reshape(samples, -1)
rmse = root_mean_squared_error(data['q_right_validate'].T, q_predict_PINN.T, multioutput='raw_values')
error = np.median(rmse)
# error = np.array(losshistory.loss_train).sum(axis=1).ravel().min()
print(f'Error: {error}')
......
No preview for this file type
src/Data/PINN/Tuner/Convergence.png

25.5 KiB | W: | H:

src/Data/PINN/Tuner/Convergence.png

22.4 KiB | W: | H:

src/Data/PINN/Tuner/Convergence.png
src/Data/PINN/Tuner/Convergence.png
src/Data/PINN/Tuner/Convergence.png
src/Data/PINN/Tuner/Convergence.png
  • 2-up
  • Swipe
  • Onion skin
No preview for this file type
No preview for this file type
src/Data/PINN/Tuner/Objective.png

74.5 KiB | W: | H:

src/Data/PINN/Tuner/Objective.png

77.7 KiB | W: | H:

src/Data/PINN/Tuner/Objective.png
src/Data/PINN/Tuner/Objective.png
src/Data/PINN/Tuner/Objective.png
src/Data/PINN/Tuner/Objective.png
  • 2-up
  • Swipe
  • Onion skin
No preview for this file type
src/Data/PINN/Tuner/PINNTunerLossHistory.png

21.4 KiB | W: | H:

src/Data/PINN/Tuner/PINNTunerLossHistory.png

20.5 KiB | W: | H:

src/Data/PINN/Tuner/PINNTunerLossHistory.png
src/Data/PINN/Tuner/PINNTunerLossHistory.png
src/Data/PINN/Tuner/PINNTunerLossHistory.png
src/Data/PINN/Tuner/PINNTunerLossHistory.png
  • 2-up
  • Swipe
  • Onion skin
No preview for this file type
src/Data/PINN/Tuner/PINNTunerLossHistory_splitted.png

54 KiB | W: | H:

src/Data/PINN/Tuner/PINNTunerLossHistory_splitted.png

51.5 KiB | W: | H:

src/Data/PINN/Tuner/PINNTunerLossHistory_splitted.png
src/Data/PINN/Tuner/PINNTunerLossHistory_splitted.png
src/Data/PINN/Tuner/PINNTunerLossHistory_splitted.png
src/Data/PINN/Tuner/PINNTunerLossHistory_splitted.png
  • 2-up
  • Swipe
  • Onion skin
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment