# Learning the Kernel
This project considers Whitham-type systems,
$$
u_t+2u\,u_x+\mathcal{K}*u_x=0,
$$
The goal is to **learn the nonlocal kernel** $\widehat{\mathcal{K}}(k)$ from data $u_{\rm data}(x,t)$:
# 1) Direct (spectral) deconvolution — one-shot closed form
Move known terms to the left and take Fourier in $x$:
$$
y(x,t):=-u_t-2u\,u_x=(\mathcal{K}*u_x)(x,t) \;\;\Longrightarrow\;\;
\widehat{y}(k,t)=\widehat{\mathcal{K}}(k)\,\big(i k\,\widehat{u}(k,t)\big).
$$
For each wavenumber $k$, stack times $t_1,\dots,t_M$ and solve a scalar Tikhonov least-squares:
$$
\widehat{\mathcal{K}}(k)
=\underset{K\in\mathbb{C}}{\arg\min}\sum_{m=1}^M\big|\widehat{y}(k,t_m)-K\,G(k,t_m)\big|^2+\lambda |K|^2,
\quad G(k,t)=i k\,\widehat{u}(k,t).
$$
This has the closed-form “Wiener” solution
$$
\widehat{\mathcal{K}}(k)=\frac{\sum_{m}\overline{G(k,t_m)}\,\widehat{y}(k,t_m)}{\sum_{m}|G(k,t_m)|^2+\lambda}.
$$
Choose $\lambda\ge 0$ (small) to stabilize noisy or weakly excited $k$-modes.
Practical tips:
- Estimate $u_x$ spectrally; estimate $u_t$ with a high-order time scheme or Savitzky–Golay smoothing in time before Fourier transforming.
- Enforce physics: project to real-even $\widehat{\mathcal{K}}(k)$ (average $k$ with $-k$), and if desired enforce nonnegativity via $\widehat{\mathcal{K}}\leftarrow\max\{0,\mathrm{Re}\,\widehat{\mathcal{K}}\}$.
- Optional asymptotics regularization (if you believe water-wave physics): near $k=0$,
$$
\widehat{\mathcal{K}}(k)=1-\tfrac{1}{6}k^2+\tfrac{19}{360}k^4+O(k^6),
$$
and as $|k|\to\infty$, $\widehat{\mathcal{K}}(k)\sim |k|^{-1/2}$. Penalize deviations in those regimes.
A super-simple cross-check: linearize $u_t+\mathcal{K}*u_x=0$. Plane waves $e^{i(kx-\omega t)}$ give $\omega(k)=k\,\widehat{\mathcal{K}}(k)$. So from a space-time FFT, extract the ridge $\omega(k)$ and verify $\widehat{\mathcal{K}}(k)\approx \omega(k)/k$.
# 2) Physics-informed fitting of a constrained ansatz
Parameterize $\widehat{\mathcal{K}}_\theta(k)$ and fit $\theta$ by minimizing the PDE residual:
$$
\mathcal{R}_\theta(x,t)=u_t+2u\,u_x+\mathcal{F}^{-1}\!\Big[\widehat{\mathcal{K}}_\theta(k)\,(ik)\,\widehat{u}(k,t)\Big](x),
\quad \min_\theta \sum_{(x,t)}|\mathcal{R}_\theta(x,t)|^2.
$$
Good choices for $\widehat{\mathcal{K}}_\theta$:
- **Chebyshev/Rational basis** on $k\in[0,k_{\max}]$ with soft constraints for small/large-$k$ behavior.
- **Monotone/positive** parameterization, e.g. $\widehat{\mathcal{K}}_\theta(k)=\mathrm{softplus}(s_\theta(k))$.
- **Baseline-plus-correction**: $\widehat{\mathcal{K}}_\theta(k)=\sqrt{\tanh k/k}\cdot(1+\delta_\theta(k))$ to learn deviations from classical Whitham.
This route is robust when $u_t$ is hard to differentiate (use weak forms: test against smooth $\varphi$, integrate by parts to move derivatives off $u$) and when you want to fuse multiple experiments/BCs.
---
## What you get out
- A **data-driven dispersion** $\widehat{\mathcal{K}}(k)$ (and $K(x)$ via inverse FFT) that you can drop back into Whitham-type models.
- Immediate **validation**: compare learned $\omega(k)/k$ to spatio-temporal spectral ridges; simulate with the learned kernel and compare wave speeds/solitary-wave profiles.