Add avoidance and intrusion number computation#279
Open
schroedtert wants to merge 20 commits into
Open
Conversation
4ea73ee to
6bfa513
Compare
Collaborator
Author
|
@chraibi can you take over and add the documentation for the functions? |
Due to Python operator precedence, v_i - v_j / ||v_i - v_j|| was computing v_i - (v_j / ||v_i - v_j||) instead of the intended (v_i - v_j) / ||v_i - v_j||. Split into two steps to make the order of operations explicit.
cos_alpha should be the dot product of the unit position difference (e_v) and the unit relative velocity (v_rel_hat). Previously, it was divided by (distance * v_rel_norm), which introduced a spurious 1/d factor since e_v was already a unit vector. Also rename v_rel_norm to delta_v_norm to clarify it is the magnitude of the actual relative velocity (used in the TTC denominator), not the norm of the unit vector.
Per Cordes2024 Eq. 1, the neighbor set N_i is restricted to agents within r_ij <= 3*r_soc. Without this filter, distant agents contribute small but accumulating spurious values to the intrusion number.
Also update the API docs section header from "Other" to "Dimensionless Numbers".
Module docstring with paper reference, and per-function docstrings with the mathematical definitions (Eqs. 1 and 2 from Cordes et al. 2024), parameter descriptions, and return types. Follows the existing rst/math style used in other PedPy modules.
- Intrusion: two-agent known distance, neighbor cutoff exclusion, three-agent sum, and MAX aggregation method - Avoidance: head-on collision with analytically known TTC, diverging agents with zero avoidance
Demonstrates compute_intrusion and compute_avoidance using the existing bottleneck demo data. Shows per-agent results and temporal evolution plots of the frame-averaged dimensionless numbers.
a5af5bb to
2e990de
Compare
- Use column constants (ID_COL, FRAME_COL, etc.) instead of string literals in _compute_individual_distances - Use inner join instead of outer join for self-merge (same DataFrame) - Make compute_individual_distances public (used across modules) - Guard division by zero: filter distance > l_min in intrusion, skip distance == 0 and delta_v_norm == 0 pairs in avoidance - Fix SettingWithCopyWarning: use .loc[] and .copy() - Simplify cos_alpha computation: use np.sum directly instead of converting to list and back - Compute v_rel_hat only for valid pairs (nonzero relative velocity) - Fix methods.rst section adornment level for Dimensionless Numbers
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Change radius default from 0.2 to 0.4 to match paper (ℓ_soc = 0.4m) - Export INTRUSION_COL and AVOIDANCE_COL from pedpy.__init__ - Document that agents at exactly l_min distance are excluded
Codecov Report✅ All modified and coverable lines are covered by tests. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.