Beispiel #1
0
    def test_symmetry(self) -> None:
        attrs = {
            "simulated_ego_states": torch.ones(20, 7),
            "recorded_ego_states": torch.full((20, 7), 2.0),
        }
        sim_output = mock.Mock(**attrs)
        metric = metrics.DistanceToRefTrajectoryMetric()
        result = metric.compute(sim_output)

        attrs = {
            "simulated_ego_states": torch.full((20, 7), 2.0),
            "recorded_ego_states": torch.ones(20, 7),
        }
        sim_output = mock.Mock(**attrs)
        metric = metrics.DistanceToRefTrajectoryMetric()
        result_switch = metric.compute(sim_output)
        self.assertEqual(result.sum(), result_switch.sum())
Beispiel #2
0
 def build_metrics(self) -> List[metrics.SupportsMetricCompute]:
     """Returns a list of metrics that will be computed.
     """
     return [
         metrics.DisplacementErrorL2Metric(),
         metrics.DistanceToRefTrajectoryMetric(),
         metrics.CollisionFrontMetric(),
         metrics.CollisionRearMetric(),
         metrics.CollisionSideMetric()
     ]
 def test_more_simulation_than_observation(self) -> None:
     timesteps = 20
     attrs = {
         "simulated_ego_states": torch.ones(timesteps + 20, 7),
         "recorded_ego_states": torch.ones(timesteps, 7),
     }
     sim_output = mock.Mock(**attrs)
     metric = metrics.DistanceToRefTrajectoryMetric()
     with self.assertRaisesRegex(ValueError, "More simulated timesteps than observed"):
         _ = metric.compute(sim_output)
Beispiel #4
0
 def test_half_trajectories(self) -> None:
     observed_trajectory = torch.ones(40, 7)
     observed_trajectory[20:, :] += 1.0
     attrs = {
         "simulated_ego_states": torch.ones(40, 7),
         "recorded_ego_states": observed_trajectory,
     }
     sim_output = mock.Mock(**attrs)
     metric = metrics.DistanceToRefTrajectoryMetric()
     result = metric.compute(sim_output)
     self.assertEqual(len(torch.unique(result)), 1)
Beispiel #5
0
    def test_larger_observed_ego(self) -> None:
        simulated_steps = 20
        attrs = {
            "simulated_ego_states": torch.ones(simulated_steps, 7),
            "recorded_ego_states": torch.ones(50, 7),
        }
        sim_output = mock.Mock(**attrs)
        metric = metrics.DistanceToRefTrajectoryMetric()
        result = metric.compute(sim_output)
        self.assertEqual(result.sum(), 0.)

        # Default fraction should be 80% of the samples
        simulated_steps_fraction = int(simulated_steps * 0.8)
        self.assertEqual(len(result), simulated_steps_fraction)
Beispiel #6
0
    def test_different_fraction(self) -> None:
        simulated_steps = 20
        scene_fraction = 0.5
        attrs = {
            "simulated_ego_states": torch.ones(simulated_steps, 7),
            "recorded_ego_states": torch.ones(simulated_steps, 7),
        }
        sim_output = mock.Mock(**attrs)
        metric = metrics.DistanceToRefTrajectoryMetric(scene_fraction)
        result = metric.compute(sim_output)

        simulated_steps_fraction = int(simulated_steps * scene_fraction)
        self.assertEqual(len(result), simulated_steps_fraction)
        self.assertEqual(result.sum(), 0.)
Beispiel #7
0
    def test_parallel_trajectory(self) -> None:
        simulated_steps = 20
        attrs = {
            "simulated_ego_states": torch.ones(simulated_steps, 7),
            "recorded_ego_states": torch.full((20, 7), 2.0),
        }
        sim_output = mock.Mock(**attrs)
        metric = metrics.DistanceToRefTrajectoryMetric()
        result = metric.compute(sim_output)

        # Default fraction should be 80% of the samples
        simulated_steps_fraction = int(simulated_steps * 0.8)
        self.assertEqual(len(result), simulated_steps_fraction)
        self.assertEqual(len(torch.unique(result)), 1)
        self.assertAlmostEqual(torch.unique(result).item(), 1.4142, 4)