# /// script
# requires-python = ">=3.11"
# dependencies = []
# ///
"""Learn potential stiffness and Fourier transport from short fields, then predict new waves."""
from math import exp, sqrt
from pathlib import Path
import sys
sys.path.insert(0, str(Path(__file__).resolve().parents[1]/"reference"))
from waves import predictor, series, train

theta,_ = train(series(23,3))
print(f"mobility {exp(theta[0]):.4f}, gradient stiffness {exp(theta[1]):.4f}, skew amplitude {theta[2]:.4f}")
path = series(93,1,frames=16)[0]
u = path[0]
for _ in path[1:]:
    u = predictor(theta,len(u))(u)
error = sqrt(sum((a-b)**2 for a,b in zip(u,path[-1]))/sum(a*a for a in path[-1]))
print(f"held-out 15-step relative field error {error:.6f}")
