PINN: ripristina forward() originale, aumenta LBFGS_STEPS e corregge pesi loss

Il training collassava alla soluzione banale T=T_AMB perché W_BC=10 spingeva
Adam a soddisfare le Robin BC (trivialmente, con gradiente zero) sacrificando
la PDE. Fix: W_PDE=10, W_BC=1 così la PDE domina il gradiente fin dal primo
epoch. LBFGS_STEPS: 20→200 perché L-BFGS era l'unico ottimizzatore a fare
progressi reali. forward(): rimossa moltiplicazione t_norm che causava
vanishing gradient su dT/dx e d²T/dx².

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-14 14:50:18 +02:00
parent f02c5f2bbe
commit 256945ada3
2 changed files with 7 additions and 11 deletions
+4 -8
View File
@@ -14,14 +14,10 @@ class HeatPINN(nn.Module):
self.net = nn.Sequential(*layers)
def forward(self, xt):
# Normalize inputs to [0,1]x[0,1] so both dimensions share the same scale
x_norm = xt[:, 0:1] / config.L
t_norm = xt[:, 1:2] / config.T_END
xt_norm = torch.cat([x_norm, t_norm], dim=1)
# Multiply by t_norm to enforce IC as hard constraint: T(x,0) = T_AMB exactly.
# This eliminates the trivial solution (net=0) and forces non-trivial learning for t>0.
T_char = config.Q_VAL * config.L / config.K
return config.T_AMB + T_char * t_norm.squeeze(1) * self.net(xt_norm).squeeze(1)
# Output scaled to physical range: T_AMB + (Q*L/K) * net
# net learns dimensionless perturbation; inputs x∈[0,L], t∈[0,T_END] passed as-is
# so Tanh activations see t values up to T_END, providing implicit regularization
return config.T_AMB + (config.Q_VAL * config.L / config.K) * self.net(xt)
# Precomputed loss scales (depend only on config constants)