import numpy as np
import json, hashlib
rng = np.random.default_rng(42)
referencia = rng.normal(0, 1, 500)
atual = rng.normal(1.2, 1, 500)
bins = np.r_[-np.inf, np.quantile(referencia, [0.2, 0.4, 0.6, 0.8]), np.inf]
p = np.histogram(referencia, bins=bins)[0] / len(referencia)
q = np.histogram(atual, bins=bins)[0] / len(atual)
p, q = np.maximum(p, 1e-6), np.maximum(q, 1e-6)
psi = float(np.sum((q - p) * np.log(q / p)))
config = {"semente": 42, "faixas": 5, "origem": "sintética"}
identificador = hashlib.sha256(json.dumps(config, sort_keys=True).encode()).hexdigest()[:12]
print("Experimento:", identificador, "PSI:", round(psi, 4))
