# /// script
# requires-python = ">=3.11"
# dependencies = []
# ///
"""Recover a stationary landscape and a circulating current from short pairs."""
from math import exp, sqrt
from pathlib import Path
from random import Random
import sys
sys.path.insert(0, str(Path(__file__).resolve().parents[1]/"reference"))
from linear import model, samples, train
from uidd import local_epr, stationary_epr

theta, _ = train(samples(91,12))
print("stationary precision", *(f"{exp(v):.4f}" for v in theta[:2]))
print(f"upper skew band {theta[4]:.4f}")
parts, sigma = model(theta)([1.,-0.5])
print("irreversible drift at (1,-0.5)", *(f"{x:.4f}" for x in parts[1]))
print(f"local total EPR {local_epr(parts[1],sigma):.4f}")
# This fitted linear model has a known Gaussian stationary law. For an observed
# process, pass equilibrated positions from independent paths or long blocks.
rng = Random(13)
std = [1/sqrt(exp(v)) for v in theta[:2]]
stationary = [[rng.gauss(0.,a) for a in std] for _ in range(4096)]
print(f"stationary mean EPR on 4096 samples {stationary_epr(stationary,model(theta)):.4f}")
