synthetic_metrics
synthetic_metrics
¶
Evaluation metrics for synthetic multimodal benchmark tasks.
compute_mode_coverage
¶
compute_mode_coverage(generated_trajectories, expert_trajectories, expert_mode_ids, num_modes, valid_mask=None)
Measure how many expert modes the generated trajectories cover.
Each valid generated trajectory is assigned to the nearest expert mode by mean L2 distance over the full trajectory. Invalid trajectories (e.g. collided with an obstacle) are excluded entirely from mode assignment, coverage, and entropy statistics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
generated_trajectories
|
ndarray
|
Predicted Cartesian trajectories (x, y). Shape (num_rollouts, num_timesteps, 2). |
required |
expert_trajectories
|
ndarray
|
Expert demonstration trajectories (x, y). Shape (num_expert, num_timesteps, 2). |
required |
expert_mode_ids
|
ndarray
|
Ground-truth mode label per expert trajectory. Shape (num_expert,). |
required |
num_modes
|
int
|
Total number of distinct behavioral modes. |
required |
valid_mask
|
ndarray | None
|
Optional boolean mask of shape (num_rollouts,). False entries are skipped. Defaults to all-True. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, float | dict[int, int]]
|
Dictionary with: "mode_coverage": fraction of modes hit (0.0 to 1.0). "mode_entropy_ratio": normalized Shannon entropy of the mode assignment distribution (1.0 = uniform, 0.0 = single mode). "per_mode_count": dict mapping mode index to assignment count. |
Source code in src/versatil/metrics/synthetic_metrics.py
compute_goal_success_rate
¶
Compute fraction of trajectories whose final position is within threshold of the goal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
generated_trajectories
|
ndarray
|
Predicted Cartesian trajectories (x, y). Shape (num_rollouts, num_timesteps, 2). |
required |
goal
|
ndarray
|
Goal Cartesian position (x, y). Shape (2,). |
required |
threshold
|
float
|
Euclidean distance threshold for success. |
0.05
|
Returns:
| Type | Description |
|---|---|
float
|
Success rate in [0.0, 1.0]. |
Source code in src/versatil/metrics/synthetic_metrics.py
compute_success_rate
¶
compute_success_rate(generated_trajectories, obstacles, mode_endpoints, goal_threshold=0.1, min_path_length=0.0)
Fraction of trajectories that avoid obstacles, actually move, and reach an expert endpoint.
A trajectory is counted successful only when all three conditions hold
- No trajectory point lies inside any obstacle rectangle.
- Cumulative path length >=
min_path_length— rejects stationary policies that trivially satisfy the endpoint check on closed-loop tasks (circle) where start == endpoint. - Its final position is within
goal_thresholdof at least one expert endpoint (per-mode mean of the final step).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
generated_trajectories
|
ndarray
|
Predicted Cartesian trajectories (x, y). Shape (num_rollouts, num_timesteps, 2). |
required |
obstacles
|
list[tuple[float, float, float, float]]
|
List of (x_min, y_min, x_max, y_max) rectangles. Empty list disables the collision check. |
required |
mode_endpoints
|
ndarray
|
Expert endpoint per mode, shape (num_modes, 2). |
required |
goal_threshold
|
float
|
Euclidean distance threshold for reaching an endpoint. |
0.1
|
min_path_length
|
float
|
Minimum cumulative path length a trajectory must travel to count as a real attempt. 0.0 disables the check. |
0.0
|
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
Dictionary with: "success_rate": overall fraction satisfying all conditions. "collision_rate": fraction that collided with an obstacle. "endpoint_reach_rate": fraction that reached any endpoint. "path_length_rate": fraction with path length >= min_path_length. |
Source code in src/versatil/metrics/synthetic_metrics.py
compute_success_masks
¶
compute_success_masks(generated_trajectories, obstacles, mode_endpoints, goal_threshold=0.1, min_path_length=0.0)
Compute per-rollout masks for synthetic success conditions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
generated_trajectories
|
ndarray
|
Predicted Cartesian trajectories (x, y). Shape (num_rollouts, num_timesteps, 2). |
required |
obstacles
|
list[tuple[float, float, float, float]]
|
List of (x_min, y_min, x_max, y_max) rectangles. Empty list disables the collision check. |
required |
mode_endpoints
|
ndarray
|
Expert endpoint per mode, shape (num_modes, 2). |
required |
goal_threshold
|
float
|
Euclidean distance threshold for reaching an endpoint. |
0.1
|
min_path_length
|
float
|
Minimum cumulative path length a trajectory must travel to count as a real attempt. 0.0 disables the check. |
0.0
|
Returns:
| Type | Description |
|---|---|
dict[str, ndarray]
|
Dictionary with: "collision_mask": True where the rollout enters an obstacle. "endpoint_reach_mask": True where the rollout reaches any endpoint. "path_length_mask": True where path length >= min_path_length. "success_mask": True where all success conditions hold. |
Source code in src/versatil/metrics/synthetic_metrics.py
compute_success_rates_from_masks
¶
Aggregate synthetic success-condition masks into rollout rates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
success_masks
|
dict[str, ndarray]
|
Dictionary produced by |
required |
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
Dictionary with: "success_rate": overall fraction satisfying all conditions. "collision_rate": fraction that collided with an obstacle. "endpoint_reach_rate": fraction that reached any endpoint. "path_length_rate": fraction with path length >= min_path_length. |
Source code in src/versatil/metrics/synthetic_metrics.py
collides_with_obstacles
¶
Per-trajectory boolean mask for any-point-inside-any-obstacle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trajectories
|
ndarray
|
Cartesian (x, y) points, shape (num_rollouts, num_timesteps, 2). |
required |
obstacles
|
list[tuple[float, float, float, float]]
|
List of (x_min, y_min, x_max, y_max) axis-aligned rectangles. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Boolean array of shape (num_rollouts,); True where the trajectory |
ndarray
|
enters at least one obstacle. All False when |
Source code in src/versatil/metrics/synthetic_metrics.py
compute_mode_endpoints
¶
Compute mean final position per expert mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expert_trajectories
|
ndarray
|
Expert trajectories, shape (num_expert, num_timesteps, 2). |
required |
expert_mode_ids
|
ndarray
|
Mode label per expert, shape (num_expert,). |
required |
num_modes
|
int
|
Total number of modes. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Array of shape (num_modes, 2) with the per-mode mean final position. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any mode in [0, num_modes) has no expert trajectories. |