Download exp2/code/time_variance.py from Kavin60606/isr-aloha-transfer-cube-experiment: direct link, hf CLI and curl.
- Browser
- Download file 2.46 kB
-
https://huggingface.co/datasets/Kavin60606/isr-aloha-transfer-cube-experiment/resolve/main/exp2/code/time_variance.py
- Command line
-
hf download hf://datasets/Kavin60606/isr-aloha-transfer-cube-experiment/exp2/code/time_variance.py
-
curl -L -o time_variance.py https://huggingface.co/datasets/Kavin60606/isr-aloha-transfer-cube-experiment/resolve/main/exp2/code/time_variance.py
2.46 kB
| import numpy as np, glob, json, sys | |
| T = sys.argv[1] if len(sys.argv) > 1 else "aloha_transfer_cube"; K = sys.argv[2] if len(sys.argv) > 2 else "keeps2_aloha_transfer_cube"; arms = sys.argv[3:] or ["aloha_transfer_cube2_uni3", "aloha_transfer_cube2_isr33_lam0"] | |
| def events(S): # S degrees [T,14]; grippers at 6 (right) and 13 (left); closing = drop by >30% of span | |
| ev = {} | |
| for name, c in [("right_grasp", 6), ("left_grasp", 13)]: | |
| g = S[:, c]; lo, hi = np.percentile(g, 5), np.percentile(g, 95); mid = (lo + hi) / 2; opened = False; ev[name] = None | |
| for i in range(5, len(g)): | |
| if g[i - 5:i].mean() > mid: opened = True | |
| if opened and g[i] < mid: ev[name] = i; break | |
| return ev | |
| rows = [] | |
| for f in sorted(glob.glob(f"trajs_{T}/ep*.npz")): | |
| d = np.load(f); S = d["state"]; ev = events(S); ep = f.split("/")[-1][:-4]; r = {"ep": ep, **{k: v for k, v in ev.items()}} | |
| for arm in arms: | |
| keep = np.load(f"{K}/{arm}/{ep}.npy") | |
| for k, v in ev.items(): r[f"{arm}:{k}"] = int(np.searchsorted(keep, v)) if v is not None else None | |
| r["idle_frac"] = float(np.mean(np.r_[0, np.linalg.norm(np.diff(S[:, :12], axis=0), axis=1)] < 0.3)); rows.append(r) | |
| def stat(key): | |
| v = np.array([r[key] for r in rows if r[key] is not None], float); return v.mean(), v.std(), v.std() / v.mean(), v.min(), v.max() | |
| print(f"{T}: {len(rows)} episodes\n") | |
| print("| event | representation | mean frame | std | CV (std/mean) | min–max |\n|---|---|---|---|---|---|") | |
| for k in ["right_grasp", "left_grasp"]: | |
| for key, lab in [(k, "raw (time)")] + [(f"{a}:{k}", a.split("_", 3)[-1]) for a in arms]: | |
| m, s, cv, lo, hi = stat(key); print(f"| {k} | {lab} | {m:.0f} | {s:.1f} | {cv:.2f} | {lo:.0f}–{hi:.0f} |") | |
| dur = [r["left_grasp"] - r["right_grasp"] for r in rows if r["left_grasp"] and r["right_grasp"]]; print(f"\nraw grasp→handover duration: mean {np.mean(dur):.0f} frames, std {np.std(dur):.0f}, CV {np.std(dur)/np.mean(dur):.2f}, range {min(dur)}–{max(dur)}") | |
| for a in arms: | |
| dur = [r[f"{a}:left_grasp"] - r[f"{a}:right_grasp"] for r in rows if r["left_grasp"] and r["right_grasp"]]; print(f"{a}: grasp→handover kept-frames: mean {np.mean(dur):.0f}, std {np.std(dur):.0f}, CV {np.std(dur)/np.mean(dur):.2f}") | |
| print(f"idle frames per episode: mean {100*np.mean([r['idle_frac'] for r in rows]):.1f} %, range {100*min(r['idle_frac'] for r in rows):.0f}–{100*max(r['idle_frac'] for r in rows):.0f} %") | |