#!/usr/bin/env python3 """Full-512-d linear probe on the cached encoder features. The figure scripts probe only the 2-3 PCA axes they draw, which understates what the representation holds. This probes the whole feature vector, which is the number to quote when asking "does the encoder know which cable this is". Episode-level split: frames inside one episode are near-duplicates, so a frame-level split would leak the answer. """ import argparse import numpy as np from sklearn.linear_model import LogisticRegression from sklearn.pipeline import make_pipeline from sklearn.preprocessing import StandardScaler ap = argparse.ArgumentParser() ap.add_argument("--cache", default="cache/cache_cable_feats.npz") ap.add_argument("--label-key", default="y") a = ap.parse_args() d = np.load(a.cache, allow_pickle=True) X, y, ep = d["feats"], d[a.label_key], d["eps"] rng = np.random.default_rng(0) tr = np.zeros(len(y), bool) for t in np.unique(y): e = np.unique(ep[y == t]) tr |= np.isin(ep, rng.choice(e, size=int(len(e) * 0.7), replace=False)) clf = make_pipeline(StandardScaler(), LogisticRegression(max_iter=5000)) clf.fit(X[tr], y[tr]) print(f" classes : {list(np.unique(y))}") print(f" frames : {tr.sum()} train / {(~tr).sum()} held out (episode-level split)") print(f" probe accuracy on the full 512-d feature : {clf.score(X[~tr], y[~tr]):.1%}" f" (chance {1 / len(np.unique(y)):.1%})")