Package exact adaptive implementation: code/examples/realRobots/Piper/eval_files/compare_adaptive_uniform_open_loop.py
Browse files
models/piper-pick-white-block-25hz-qwenpi-v3-adaptive-left-exclude-gripper-native-controls13-gb32-50k-20260905/code/examples/realRobots/Piper/eval_files/compare_adaptive_uniform_open_loop.py
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Compare adaptive and uniform checkpoints on their common 10-step prefix."""
|
| 3 |
+
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
import argparse
|
| 7 |
+
import json
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
|
| 10 |
+
import numpy as np
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def _metrics(values: np.ndarray) -> dict:
|
| 14 |
+
values = np.asarray(values, dtype=np.float64)
|
| 15 |
+
return {
|
| 16 |
+
"rmse": float(np.sqrt(np.mean(np.square(values)))),
|
| 17 |
+
"mae": float(np.mean(np.abs(values))),
|
| 18 |
+
"first_action_rmse": float(np.sqrt(np.mean(np.square(values[:, 0])))),
|
| 19 |
+
"arm_rmse": float(np.sqrt(np.mean(np.square(values[..., :6])))),
|
| 20 |
+
"gripper_rmse": float(np.sqrt(np.mean(np.square(values[..., 6])))),
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def main() -> None:
|
| 25 |
+
parser = argparse.ArgumentParser(description=__doc__)
|
| 26 |
+
parser.add_argument("adaptive_arrays", type=Path)
|
| 27 |
+
parser.add_argument("uniform_arrays", type=Path)
|
| 28 |
+
parser.add_argument("--output", type=Path, required=True)
|
| 29 |
+
args = parser.parse_args()
|
| 30 |
+
|
| 31 |
+
with np.load(args.adaptive_arrays.expanduser().resolve()) as adaptive_file:
|
| 32 |
+
adaptive = {key: adaptive_file[key] for key in adaptive_file.files}
|
| 33 |
+
with np.load(args.uniform_arrays.expanduser().resolve()) as uniform_file:
|
| 34 |
+
uniform = {key: uniform_file[key] for key in uniform_file.files}
|
| 35 |
+
np.testing.assert_array_equal(adaptive["sample_index"], uniform["sample_index"])
|
| 36 |
+
np.testing.assert_array_equal(adaptive["episode_index"], uniform["episode_index"])
|
| 37 |
+
np.testing.assert_array_equal(adaptive["frame_index"], uniform["frame_index"])
|
| 38 |
+
|
| 39 |
+
horizon = 10 # every positive-duration 13-row cubic plan guarantees ten native steps
|
| 40 |
+
adaptive_model_error = adaptive["prediction_vs_original_error"][:, :horizon]
|
| 41 |
+
adaptive_representation_error = adaptive["spline_vs_original_error"][:, :horizon]
|
| 42 |
+
uniform_model_error = uniform["prediction_vs_original_error"][:, :horizon]
|
| 43 |
+
uniform_representation_error = uniform["spline_vs_original_error"][:, :horizon]
|
| 44 |
+
adaptive_model = _metrics(adaptive_model_error)
|
| 45 |
+
uniform_model = _metrics(uniform_model_error)
|
| 46 |
+
adaptive_representation = _metrics(adaptive_representation_error)
|
| 47 |
+
uniform_representation = _metrics(uniform_representation_error)
|
| 48 |
+
report = {
|
| 49 |
+
"passed": True,
|
| 50 |
+
"comparison": "same recorded observations and common native-rate prefix",
|
| 51 |
+
"observations": int(len(adaptive["sample_index"])),
|
| 52 |
+
"horizon_steps": int(horizon),
|
| 53 |
+
"adaptive": {
|
| 54 |
+
"model_vs_original": adaptive_model,
|
| 55 |
+
"representation_vs_original": adaptive_representation,
|
| 56 |
+
},
|
| 57 |
+
"uniform": {
|
| 58 |
+
"model_vs_original": uniform_model,
|
| 59 |
+
"representation_vs_original": uniform_representation,
|
| 60 |
+
},
|
| 61 |
+
"adaptive_vs_uniform": {
|
| 62 |
+
"model_arm_rmse_reduction_fraction": (
|
| 63 |
+
1.0 - adaptive_model["arm_rmse"] / uniform_model["arm_rmse"]
|
| 64 |
+
),
|
| 65 |
+
"model_overall_rmse_reduction_fraction": (
|
| 66 |
+
1.0 - adaptive_model["rmse"] / uniform_model["rmse"]
|
| 67 |
+
),
|
| 68 |
+
"representation_arm_rmse_reduction_fraction": (
|
| 69 |
+
1.0
|
| 70 |
+
- adaptive_representation["arm_rmse"]
|
| 71 |
+
/ uniform_representation["arm_rmse"]
|
| 72 |
+
),
|
| 73 |
+
},
|
| 74 |
+
"gripper_note": (
|
| 75 |
+
"Continuous gripper error is reported separately because gripper dimension 6 is excluded "
|
| 76 |
+
"from knot placement and is projected to binary commands during deployment."
|
| 77 |
+
),
|
| 78 |
+
}
|
| 79 |
+
output = args.output.expanduser().resolve()
|
| 80 |
+
output.parent.mkdir(parents=True, exist_ok=True)
|
| 81 |
+
output.write_text(json.dumps(report, indent=2) + "\n")
|
| 82 |
+
print(json.dumps({"output": str(output), **report["adaptive_vs_uniform"]}, indent=2))
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
if __name__ == "__main__":
|
| 86 |
+
main()
|