import numpy as np
from kstar import kstar_rank, kstar_normalized, typology_by_class

N = 148

def make(kind, rng):
    if kind == "clustered":
        c = np.array([[i * 2.0, 0] for i in range(8)])
        a = np.concatenate([rng.normal(c[i], 0.35, (N // 4, 2)) for i in [0, 2, 4, 6]])
        b = np.concatenate([rng.normal(c[i], 0.35, (N // 4, 2)) for i in [1, 3, 5, 7]])
    elif kind == "overlapped":
        a = rng.normal([0, 0], 1.0, (N, 2))
        b = rng.normal([3, 0], 1.0, (N, 2))
    else:
        a = rng.normal([0, 0], 1.0, (N, 2))
        b = rng.normal([0, 0], 1.0, (N, 2))
    return np.vstack([a, b]), np.array([1] * len(a) + [0] * len(b))

def band(g):
    return "Fractured" if g > 0.5 else "Clustered" if g < -0.5 else "Overlapped"

for kind in ["clustered", "overlapped", "fractured"]:
    skews = []
    for seed in range(10):
        X, y = make(kind, np.random.default_rng(seed))
        t = typology_by_class(kstar_normalized(kstar_rank(X, y), y), y)
        skews.append(np.mean([t[c]["skewness"] for c in t]))
    med = float(np.median(skews))
    print(f"{kind:<11} median skew over 10 draws {med:+.2f}  ->  {band(med)}")
