Function Signature
Concept
The benchmarking step evaluates spatial precision by measuring how much the actual path deviates from a theoretical perfect path:Implementation
analysis_pipeline.py
Algorithm Breakdown
Calculate Point-to-Line Distance
For each point in the trajectory, compute perpendicular distance to the ideal line.The distance from point p to line defined by points a and b is:Formula:
The cross product gives a vector perpendicular to the line, whose magnitude equals the distance times the line length.
Output Structure
The function returns a dictionary with two keys:| Key | Type | Description | Range |
|---|---|---|---|
desviacion_avg | float | Mean perpendicular distance from ideal line | 0 - ∞ |
precision | float | Percentage score (100 = perfect) | 0 - 100 |
Example Output
- Average deviation of 2.35 units from the ideal path
- Precision score of 76.5% (good, but not excellent)
Visual Interpretation
- Excellent (>90%)
- Good (75-90%)
- Poor (<75%)
Edge Cases
Start and End Points Identical
Start and End Points Identical
If the surgeon returns to the starting position, the ideal line has zero length. The function handles this by returning the distance from each point to the start:
Single Point Trajectory
Single Point Trajectory
If there’s only one movement, deviation and precision will both be 0 and 100 respectively, since there’s no deviation from a point.
Very High Deviation
Very High Deviation
The
max(0, ...) ensures precision never goes negative, even if average deviation is very high.Limitations
Future Enhancements
Potential improvements to the benchmarking system:- Expert trajectory comparison: Compare against paths taken by expert surgeons
- Anatomical constraints: Account for obstacle avoidance requirements
- Task-specific ideals: Different ideal paths for different surgical procedures
- Time-weighted deviations: Penalize deviations during critical moments more heavily
Clinical Significance
High precision (>85%) indicates:Strong Spatial Planning
The surgeon planned the optimal path before executing
Steady Execution
Minimal hand tremor and good motor control
Efficient Movement
Direct paths reduce procedure time and tissue trauma
Consistent Skill
Reproducible performance across multiple attempts
Performance
The list comprehension iterates through all movements, but the distance calculation is fast:- Vector operations: NumPy cross product and norm are C-optimized
- No nested loops: O(n) complexity
- Minimal memory: Only stores deviation values
Next Step
With precision quantified, the pipeline moves to risk analysis:Risk Analysis
Identify critical events and dangerous spatial patterns