Package exact adaptive implementation: code/examples/realRobots/Piper/eval_files/visualize_adaptive_bspline_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/visualize_adaptive_bspline_open_loop.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Visualize adaptive-vs-uniform open-loop errors on the common prefix."""
|
| 3 |
+
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
import argparse
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
|
| 9 |
+
import matplotlib.pyplot as plt
|
| 10 |
+
import numpy as np
|
| 11 |
+
|
| 12 |
+
ACTION_NAMES = ["J1", "J2", "J3", "J4", "J5", "J6", "Gripper"]
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def _rmse(values, axis):
|
| 16 |
+
return np.sqrt(np.mean(np.square(np.asarray(values, dtype=np.float64)), axis=axis))
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def main() -> None:
|
| 20 |
+
parser = argparse.ArgumentParser(description=__doc__)
|
| 21 |
+
parser.add_argument("adaptive_arrays", type=Path)
|
| 22 |
+
parser.add_argument("uniform_arrays", type=Path)
|
| 23 |
+
parser.add_argument("--output", type=Path, required=True)
|
| 24 |
+
args = parser.parse_args()
|
| 25 |
+
with np.load(args.adaptive_arrays.expanduser().resolve()) as handle:
|
| 26 |
+
adaptive = {key: handle[key] for key in handle.files}
|
| 27 |
+
with np.load(args.uniform_arrays.expanduser().resolve()) as handle:
|
| 28 |
+
uniform = {key: handle[key] for key in handle.files}
|
| 29 |
+
np.testing.assert_array_equal(adaptive["sample_index"], uniform["sample_index"])
|
| 30 |
+
horizon = 10
|
| 31 |
+
uniform_model = uniform["prediction_vs_original_error"][:, :horizon]
|
| 32 |
+
uniform_representation = uniform["spline_vs_original_error"][:, :horizon]
|
| 33 |
+
adaptive_model = adaptive["prediction_vs_original_error"][:, :horizon]
|
| 34 |
+
adaptive_representation = adaptive["spline_vs_original_error"][:, :horizon]
|
| 35 |
+
|
| 36 |
+
fig, axes = plt.subplots(2, 2, figsize=(14, 9), constrained_layout=True)
|
| 37 |
+
steps = np.arange(horizon)
|
| 38 |
+
axes[0, 0].plot(steps, _rmse(adaptive_model[..., :6], axis=(0, 2)), marker="o", label="Adaptive")
|
| 39 |
+
axes[0, 0].plot(steps, _rmse(uniform_model[..., :6], axis=(0, 2)), marker="o", label="Uniform-left")
|
| 40 |
+
axes[0, 0].set(title="Policy arm RMSE by horizon", xlabel="25 Hz action step", ylabel="RMSE")
|
| 41 |
+
axes[0, 0].legend()
|
| 42 |
+
axes[0, 0].grid(alpha=0.25)
|
| 43 |
+
|
| 44 |
+
axes[0, 1].plot(steps, _rmse(adaptive_representation[..., :6], axis=(0, 2)), marker="o", label="Adaptive")
|
| 45 |
+
axes[0, 1].plot(steps, _rmse(uniform_representation[..., :6], axis=(0, 2)), marker="o", label="Uniform-left")
|
| 46 |
+
axes[0, 1].set(title="Representation-only arm RMSE", xlabel="25 Hz action step", ylabel="RMSE")
|
| 47 |
+
axes[0, 1].legend()
|
| 48 |
+
axes[0, 1].grid(alpha=0.25)
|
| 49 |
+
|
| 50 |
+
width = 0.36
|
| 51 |
+
dims = np.arange(7)
|
| 52 |
+
axes[1, 0].bar(dims - width / 2, _rmse(adaptive_model, axis=(0, 1)), width, label="Adaptive")
|
| 53 |
+
axes[1, 0].bar(dims + width / 2, _rmse(uniform_model, axis=(0, 1)), width, label="Uniform-left")
|
| 54 |
+
axes[1, 0].set_xticks(dims, ACTION_NAMES)
|
| 55 |
+
axes[1, 0].set(title="Policy RMSE per action dimension", ylabel="RMSE")
|
| 56 |
+
axes[1, 0].legend()
|
| 57 |
+
axes[1, 0].grid(axis="y", alpha=0.25)
|
| 58 |
+
|
| 59 |
+
duration_error = adaptive["duration_error"].reshape(-1)
|
| 60 |
+
bins = np.arange(duration_error.min() - 0.5, duration_error.max() + 1.5)
|
| 61 |
+
axes[1, 1].hist(duration_error, bins=bins, density=True, color="#5b8ff9", alpha=0.85)
|
| 62 |
+
axes[1, 1].set(
|
| 63 |
+
title="Adaptive predicted knot-duration error",
|
| 64 |
+
xlabel="Predicted − target duration (25 Hz steps)",
|
| 65 |
+
ylabel="Fraction",
|
| 66 |
+
)
|
| 67 |
+
axes[1, 1].grid(axis="y", alpha=0.25)
|
| 68 |
+
fig.suptitle(
|
| 69 |
+
f"Piper QwenPI_v3: adaptive-left vs uniform-left ({len(adaptive_model):,} observations)",
|
| 70 |
+
fontsize=15,
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
output = args.output.expanduser().resolve()
|
| 74 |
+
output.parent.mkdir(parents=True, exist_ok=True)
|
| 75 |
+
fig.savefig(output, dpi=180)
|
| 76 |
+
fig.savefig(output.with_suffix(".svg"))
|
| 77 |
+
plt.close(fig)
|
| 78 |
+
print(output)
|
| 79 |
+
print(output.with_suffix(".svg"))
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
if __name__ == "__main__":
|
| 83 |
+
main()
|