Skip to content

fix(checks): duration-weight final_pose_speed and retain on sparse streams - #701

Merged
kstonekuan merged 3 commits into
Hebbian-Robotics:mainfrom
shobhitagnihotri69:fix/trajectory-metrics-final-pose-weighting
Oct 7, 2026
Merged

kstonekuan merged 3 commits into
Hebbian-Robotics:mainfrom
shobhitagnihotri69:fix/trajectory-metrics-final-pose-weighting

Conversation

@shobhitagnihotri69

@shobhitagnihotri69 shobhitagnihotri69 commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Closes #700

Summary

  • Retain final_pose_speed on low-frequency / sparse streams: final_window_mask previously matched against step start timestamps (profile.stamps_ns[:-1]), silently dropping final_pose_speed and final_pose_unsettled_ratio whenever the step period exceeded final_pose_window_s (e.g. 1 Hz streams with the default 0.5s window). Steps ending after the window start now represent the settling motion, with a fallback to the last measured step.
  • Duration-weight final_pose_speed: previously computed using unweighted np.mean(profile.speeds[final_window_mask]), which violated HFlow's sampling-invariance principle and skewed under irregular sampling or jitter. final_speed is now weighted by profile.step_durations_s, matching mean_velocity.
  • Identity on whole-window episodes: when the final window covers the full episode, duration-weighting guarantees final_pose_speed matches mean_velocity identically and final_pose_unsettled_ratio evaluates to 1.0.
  • Regression coverage: added tests to tests/test_checks.py verifying that low-frequency streams emit final_pose_speed and that duration weighting matches mean_velocity on full-window episodes.

Testing

  • uv run ruff check src/hflow/checks.py tests/test_checks.py (passes)
  • uv run ruff format --check (passes)
  • uv run ty check (passes)
  • uv run pytest tests/test_checks.py -k trajectory_metrics (7 passed)
  • uv run pytest -m "not slow" -q (2483 passed, 49 skipped)

@greptile-apps

greptile-apps Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Changes how trajectory metrics weight motion data.

This PR appears safe to merge; no blocking issues remain.

What we checked:

  • Sparse streams retain final speed: A finite final step overlaps a positive final window. Its speed is still included even when samples arrive less often than the window length.
Summary

This PR weights final_pose_speed by each step’s time inside the final window. Sparse streams retain the metric when their final motion can be measured.

  • Final-pose speed reflects time spent moving near the episode's end.

Reviews (4) · Last reviewed commit: "fix(checks): omit final_pose_speed when ..." · Reviewed by Greptile

Comment thread src/hflow/checks.py Outdated
Comment thread tests/test_checks.py
@shobhitagnihotri69
shobhitagnihotri69 force-pushed the fix/trajectory-metrics-final-pose-weighting branch from 806015b to bb2c352 Compare October 7, 2026 04:19
Comment thread src/hflow/checks.py Outdated

@kstonekuan kstonekuan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, the overlap weighting is right and fixes both halves of #700. One change: drop the fallback to the last measured step. With overlap weighting, a sparse stream's final step already overlaps the window, so the fallback only fires when the final steps are unmeasurable (non-finite). Then it reports speed from earlier in the episode as the final pose. Omitting the measurement is the honest answer there. Please also add a test for that case.

@kstonekuan kstonekuan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, merging.

@kstonekuan
kstonekuan merged commit 23ca744 into Hebbian-Robotics:main Oct 7, 2026
3 checks passed
@shobhitagnihotri69

Copy link
Copy Markdown
Contributor Author

Thanks very much for merging this pr looking forward to do more contribution

@kstonekuan kstonekuan mentioned this pull request Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: trajectory_metrics silently omits final_pose_speed on low-frequency streams and skews final_pose_unsettled_ratio with unweighted np.mean

2 participants