Skip to content

A Fredholm integral equation of the second kind

PINN fredholm_integral_equation.py

An equation in which the unknown function appears both outside and inside an integral. There is nothing to differentiate; the integral itself is part of the loss.

The network's u(x) as an orange line during training, against the dashed exact sin(pi x) on [0, 1]: a nearly flat curve at the first epochs that bends into the sine within a few hundred epochs, with the epoch counter running from 0 to 50000.

The network's \(u(x)\) during training, epochs 0 to 50 000, against the exact \(\sin\pi x\) (dashed).

The problem

\[u(x) = f(x) + \int_0^1 x\,t\;u(t)\,dt,\qquad x\in[0,1],\qquad f(x)=\sin\pi x-\frac{x}{\pi},\]

with the exact solution \(u^\*=\sin\pi x\), since \(\int_0^1 t\sin\pi t\,dt=1/\pi\). The kernel \(x\,t\) separates, so the integral is \(x\) times one number:

\[\int_0^1 x\,t\,u(t)\,dt = x\,C,\qquad C=\int_0^1 t\,u(t)\,dt .\]

The jNO code

(x * u).integrate() evaluates \(t\,u(t)\) at all mesh nodes and reduces it to the scalar \(C\); multiplying by the outer x broadcasts it back to the collocation points. Both uses of the network share its parameters, so the gradient flows through both:

u = net(x)
C = (x * u).integrate()  # ∫₀¹ t u(t) dt: one number, whatever x is
residual = u - f - x * C

Result

After 50 000 Adam steps the network matches \(\sin\pi x\) to rel. \(L^2=9.3\times10^{-5}\); the error falls below 1 % by epoch 300.

Full script

The whole script, as it runs in the tests
"""Fredholm integral equation of the second kind, u(x) = f(x) + x ∫₀¹ t u(t) dt, solved with a PINN."""

import foundax
import jax
import optax

import jno

run = jno.setup(__file__)
π, sin = jno.np.pi, jno.np.sin

d = jno.Path(0.0, 0.0).line_to(1.0, 0.0).curve(size=0.01).domain()
x, _ = d.variable("interior")
f = sin(π * x) - x / π  # chosen so that u = sin(πx) solves it

net = jno.nn(foundax.mlp(in_features=1, hidden_dims=64, num_layers=4, activation=jax.nn.tanh, key=jax.random.PRNGKey(0)))
net.optimizer(optax.adam(optax.exponential_decay(1e-3, 5_000, 0.5, end_value=1e-5)))

u = net(x)
C = (x * u).integrate()  # ∫₀¹ t u(t) dt: one number, whatever x is
residual = u - f - x * C

crux = jno.core([residual.mse])
crux.solve(50_000)

u_h, u_ref = crux.eval([u, sin(π * x)])
rel_l2 = float(jax.numpy.linalg.norm(u_h - u_ref) / jax.numpy.linalg.norm(u_ref))  # reference: sin(πx)
print(f"Relative L2 error: {rel_l2:.4e}")
assert rel_l2 < 0.05, f"relative L2 error too large: {rel_l2:.3e}"