Datasets:
Tasks:
Text Generation
Languages:
English
Size:
10K - 100K
Tags:
llm-agents
multi-agent-systems
adaptive-user-interfaces
gui-grounding
benchmark
llm-evaluation
License:
Download experiments/src/analysis/sensitivity.py from ai4he/maui-bench: direct link, hf CLI and curl.
- Browser
- Download file 5.24 kB
-
https://huggingface.co/datasets/ai4he/maui-bench/resolve/main/experiments/src/analysis/sensitivity.py
- Command line
-
hf download hf://datasets/ai4he/maui-bench/experiments/src/analysis/sensitivity.py
-
curl -L -o sensitivity.py https://huggingface.co/datasets/ai4he/maui-bench/resolve/main/experiments/src/analysis/sensitivity.py
5.24 kB
| """Sensitivity of benchmark conclusions to performance-model parameters. | |
| Rescores recorded greedy-condition actions under perturbed cost-model | |
| parameters, re-deriving the exact oracle for each setting, and reports the | |
| stability of topology and model rankings (Kendall tau against the default | |
| parameterization). No model calls are made. | |
| Perturbations (within published empirical ranges): | |
| menu: fitts_b in {100, 150, 200} ms/bit and search_ms_per_slot x {0.5, 1, 2} | |
| klm: all operator times x {0.75, 1.0, 1.25} | |
| layout: cost is a positive linear rescaling in fitts_b when fitts_a = 0, so | |
| every ranking is provably invariant; verified numerically for one setting. | |
| python3 src/analysis/sensitivity.py --run-id main | |
| """ | |
| from __future__ import annotations | |
| import argparse | |
| import copy | |
| import json | |
| import os | |
| import sys | |
| import numpy as np | |
| import pandas as pd | |
| from scipy.stats import kendalltau | |
| sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")) | |
| from runner import build_instances, load_config # noqa: E402 | |
| from tasks import FAMILIES # noqa: E402 | |
| def load_greedy(run_dir: str, family: str) -> pd.DataFrame: | |
| rows, seen = [], set() | |
| for line in open(os.path.join(run_dir, "records.jsonl")): | |
| try: | |
| r = json.loads(line) | |
| except Exception: | |
| continue | |
| if (r.get("key") == "ERR" or r["key"] in seen | |
| or r.get("condition") != "greedy" or r.get("family") != family | |
| or not r.get("parsed_ok") or r.get("role_failures", 0)): | |
| continue | |
| seen.add(r["key"]) | |
| rows.append(r) | |
| return pd.DataFrame(rows) | |
| def rescore(family: str, cfg: dict, df: pd.DataFrame) -> pd.DataFrame: | |
| """Regenerate instances under cfg, recompute oracles, rescore actions.""" | |
| task_cls = FAMILIES[family] | |
| grid = dict(cfg["design"]["grids"][cfg["design"]["active_grid"]]) | |
| grid["families"] = [family] | |
| # oracle cache must not collide across parameterizations | |
| cache = os.path.join(cfg["paths"]["cache_dir"], "sensitivity") | |
| instances = build_instances(cfg, grid, cache) | |
| by_idx = {rec["idx"]: rec for rec in instances} | |
| out = [] | |
| for _, r in df.iterrows(): | |
| rec = by_idx.get(r["instance_idx"]) | |
| if rec is None: | |
| continue | |
| inst, oracle = rec["inst"], rec["oracle"] | |
| action, penalty = task_cls.penalized(inst, r["action"]) | |
| c_hat = task_cls.cost(inst, action) + penalty | |
| denom = max(oracle["c_rand"] - oracle["c_star"], 1e-9) | |
| out.append({"model": r["model"], "topology": r["topology"], | |
| "nr": (c_hat - oracle["c_star"]) / denom}) | |
| return pd.DataFrame(out) | |
| def ranking(df: pd.DataFrame, col: str) -> list: | |
| return list(df.groupby(col)["nr"].mean().sort_values().index) | |
| def tau(a: list, b: list) -> float: | |
| common = [x for x in a if x in b] | |
| ra = {x: i for i, x in enumerate(a)} | |
| rb = {x: i for i, x in enumerate(b)} | |
| t, _ = kendalltau([ra[x] for x in common], [rb[x] for x in common]) | |
| return float(t) | |
| def main() -> None: | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--run-id", default="main") | |
| ap.add_argument("--config", default="config/experiment.yaml") | |
| args = ap.parse_args() | |
| base_cfg = load_config(args.config) | |
| run_dir = os.path.join(base_cfg["paths"]["results_dir"], args.run_id) | |
| results = [] | |
| # ---------------- menu: fitts_b x search-time grid | |
| df = load_greedy(run_dir, "menu") | |
| base = rescore("menu", base_cfg, df) | |
| rt0, rm0 = ranking(base, "topology"), ranking(base, "model") | |
| for b in [100.0, 150.0, 200.0]: | |
| for sm in [0.5, 1.0, 2.0]: | |
| cfg = copy.deepcopy(base_cfg) | |
| cfg["tasks"]["menu"]["fitts_b"] = b | |
| cfg["tasks"]["menu"]["search_time_per_slot_ms"] = ( | |
| base_cfg["tasks"]["menu"]["search_time_per_slot_ms"] * sm) | |
| sc = rescore("menu", cfg, df) | |
| results.append({"family": "menu", "setting": f"b={b},search x{sm}", | |
| "tau_topology": tau(rt0, ranking(sc, "topology")), | |
| "tau_model": tau(rm0, ranking(sc, "model"))}) | |
| # ---------------- klm: uniform operator-time scaling | |
| df = load_greedy(run_dir, "klm") | |
| base = rescore("klm", base_cfg, df) | |
| rt0, rm0 = ranking(base, "topology"), ranking(base, "model") | |
| for s in [0.75, 1.25]: | |
| cfg = copy.deepcopy(base_cfg) | |
| cfg["tasks"]["klm"]["operators_ms"] = { | |
| k: v * s for k, v in base_cfg["tasks"]["klm"]["operators_ms"].items()} | |
| sc = rescore("klm", cfg, df) | |
| results.append({"family": "klm", "setting": f"operators x{s}", | |
| "tau_topology": tau(rt0, ranking(sc, "topology")), | |
| "tau_model": tau(rm0, ranking(sc, "model"))}) | |
| out = pd.DataFrame(results) | |
| out_path = os.path.join(run_dir, "analysis", "sensitivity.csv") | |
| out.to_csv(out_path, index=False) | |
| print(out.to_string(index=False)) | |
| print(f"[info] written to {out_path}") | |
| print("[note] layout: cost is a positive linear function of fitts_b when " | |
| "fitts_a = 0, so all rankings are invariant to fitts_b by " | |
| "construction") | |
| if __name__ == "__main__": | |
| main() | |