$ cd ../
PINNs: neural networks that solve differential equations — bash

user@devops:~$ cat README.md

PINNs: neural networks that solve differential equations

# Description

PINNs (Raissi et al. 2019) implemented from scratch in PyTorch, no DeepXDE/PyDreo: a network trained to satisfy the ODE on 256 collocation points, derivatives via autograd and the equation as the loss. Problem 1: logistic u' = r u (1 − u/K) with hard BC u(t) = u0 + t·N(t) (the initial condition is baked into the architecture) — test MSE 1.4e-7 in 6.6 s (4 000 Adam + cosine iterations). Problem 2: damped oscillator m u'' + c u' + k u = 0 (ζ=0.1, ω₀=2) — the raw second-order residual does not converge on CPU (MSE 0.05); the change of variable w = e^{ζs}u turns it into a pure harmonic w'' + ω_d² w = 0, solved as a first-order system (y1' = y2, y2' = −ω_d² y1) with Fourier features k=1..6 and a 64-64 MLP (5 186 params): test MSE 7.3e-08 in 90 s. Problem 3 (physics vs data): with 12 noisy measurements (σ=0.15) on [0.5, 4.5], sweeping the residual weight λ ∈ {0, 0.1, 1, 10} gives test MSE 328.7 → 0.76: without physics the model fits the data but explodes outside the interval; the residual drops monotonically (5.6e+03 → 8.7e-02). Problem 4 (hard vs soft BC, logistic u(0)=0.9): the λ=50 penalty gets stuck on the trivial solution u≡0.9 (MSE 33.7 after 12 000 iters), λ=1 escapes at ~8 000 iters, and the hard construction converges in 4 000 while satisfying the BC by design. Findings: the BC choice matters more than the architecture; 2nd-order → 1st-order system + Fourier; the joint loss is multimodal (λ=0.1/1 fall into local minima). 7 visualizations.

# Key features

$ PINN (Raissi et al. 2019) from scratch: tanh MLP, autograd derivatives, the ODE as loss on 256 collocation points

$ Logistic u' = r u (1 − u/K) with hard BC u = u0 + t·N(t): test MSE 1.4e-7 in 6.6 s CPU

$ Damped oscillator m u'' + c u' + k u = 0: change of variable w = e^{ζs}u → pure harmonic w'' + ω_d² w = 0

$ 1st-order system (y1'=y2, y2'=−ω_d²y1) + Fourier features k=1..6 + 64-64 MLP (5 186 params): MSE 7.3e-8 in 90 s

$ Physics vs data: 12 noisy measurements; without physics test MSE 328.7 (explodes outside [0.5, 4.5]), with λ=10 → 0.76

$ Hard vs soft BC (u(0)=0.9): λ=50 gets stuck on u≡0.9 (MSE 33.7), λ=1 escapes at ~8 000 iters, hard converges in 4 000

$ The joint loss is multimodal: λ=0.1/1 fall into local minima that neither satisfy the ODE nor fit the data

$ 7 visualizations: collocation, solutions per problem, physics vs data, hard/soft BC, convergence, summary

# Gallery

Terminal del proyecto
PINNs: neural networks that solve differential equations - Terminal del proyecto
Puntos de colocación y condiciones iniciales
PINNs: neural networks that solve differential equations - Puntos de colocación y condiciones iniciales
PINN vs analítica: ecuación logística
PINNs: neural networks that solve differential equations - PINN vs analítica: ecuación logística
PINN vs analítica: oscilador amortiguado
PINNs: neural networks that solve differential equations - PINN vs analítica: oscilador amortiguado
Física vs datos: peso del residuo y extrapolación
PINNs: neural networks that solve differential equations - Física vs datos: peso del residuo y extrapolación
BC dura vs blanda: convergencia y atascos
PINNs: neural networks that solve differential equations - BC dura vs blanda: convergencia y atascos
Convergencia del residuo físico
PINNs: neural networks that solve differential equations - Convergencia del residuo físico
Resumen PINNs
PINNs: neural networks that solve differential equations - Resumen PINNs

# Technologies used

Python PyTorch NumPy Matplotlib