Skip to content

Commit

Permalink
Fix normalisation bug for weighted speeds
Browse files Browse the repository at this point in the history
  • Loading branch information
chraibi committed Mar 17, 2024
1 parent 76212f7 commit b43d674
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/helpers/speed_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pandas
from pedpy.column_identifier import FRAME_COL
from pedpy import SpeedMethod, WalkableArea
import logging


def _compute_gaussian_weights(x: npt.NDArray[np.float64], fwhm: float) -> npt.NDArray[np.float64]:
Expand Down Expand Up @@ -35,18 +36,15 @@ def compute_gaussian_weighted_speed_profile(
positions_x = frame_data.x.values
positions_y = frame_data.y.values
speeds = frame_data.speed.values

# distance from each grid center x/y coordinates to the pedestrian positions
distance_x = np.subtract.outer(center_x, positions_x)
distance_y = np.subtract.outer(center_y, positions_y)

distance_x_expanded = np.expand_dims(distance_x, axis=1)
distance_y_expanded = np.expand_dims(distance_y, axis=0)

distance = np.sqrt(distance_x_expanded**2 + distance_y_expanded**2)

weights = _compute_gaussian_weights(distance, fwhm)
normalized_weights = weights / np.sum(weights, axis=(0, 1), keepdims=True)
normalized_weights = weights / np.sum(weights, axis=2, keepdims=True)
weighted_speeds = np.tensordot(normalized_weights, speeds, axes=([2], [0]))
return np.array(weighted_speeds.T)

Expand Down

0 comments on commit b43d674

Please sign in to comment.