import numpy as np
from scipy.special import betaln

def nal_to_beta(f,c):
    w=c/(1-c)
    return w*f, w*(1-f)

def hellinger2(a1,b1,a2,b2):
    return 1-np.exp(betaln((a1+a2)/2,(b1+b2)/2)-0.5*(betaln(a1,b1)+betaln(a2,b2)))

def rao_approx(h2):
    return 2*np.arcsinh(np.sqrt(h2/(1-h2+1e-15)))

beliefs=[("cat_animal",0.9,0.8),("cat_pet",0.85,0.7),("cat_danger",0.1,0.6),("dog_animal",0.95,0.9),("weak_claim",0.5,0.2)]
betas=[(n,*nal_to_beta(f,c)) for n,f,c in beliefs]
print("Belief Beta params:")
for n,a,b in betas:
    print(f"  {n}: a={a:.3f} b={b:.3f}")
print("\nPairwise Rao distances:")
for i in range(len(betas)):
    for j in range(i+1,len(betas)):
        h2=hellinger2(betas[i][1],betas[i][2],betas[j][1],betas[j][2])
        d=rao_approx(h2)
        print(f"  {betas[i][0]} <-> {betas[j][0]}: H2={h2:.4f} Rao={d:.4f}")