# /// script
# requires-python = ">=3.11"
# dependencies = []
# ///
"""Fit two coefficients to timed transitions of the unit-noise Beneš diffusion."""

import sys
from math import exp
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "reference"))
from benes import fit, sample_pairs, score

training = sample_pairs([-1.2, -.55, 0., .55, 1.2], [.18, .42, .73], count=48)
held_out = sample_pairs([-.86, .29, 1.4], [.25, .64], count=64)
weights, _ = fit(training)
print(f"fitted drift amplitude {weights[0]:.3f}, noise amplitude {exp(weights[1]):.3f}")
print(f"held-out mean negative log density {score(held_out, weights):.3f}")
