Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in infractions/km calculation in compute_global_statistics #117

Closed
Kait0 opened this issue May 9, 2022 · 6 comments
Closed

Bug in infractions/km calculation in compute_global_statistics #117

Kait0 opened this issue May 9, 2022 · 6 comments

Comments

@Kait0
Copy link

Kait0 commented May 9, 2022

I think there is a bug in the computation of the infractions / km metrics in the current leaderboard repository (master):
The file is leaderboard/utils/statistics_manager.py
Function def compute_global_statistics(self, total_routes):

...
if self._registry_route_records:
        for route_record in self._registry_route_records:
                 global_record.scores['score_route'] += route_record.scores['score_route']
                 global_record.scores['score_penalty'] += route_record.scores['score_penalty']
                 global_record.scores['score_composed'] += route_record.scores['score_composed']

                 for key in global_record.infractions.keys():
                     route_length_kms = max(route_record.scores['score_route'] / 100 * route_record.meta['route_length'] / 1000.0, 0.001)
                     if isinstance(global_record.infractions[key], list):
                          global_record.infractions[key] = len(route_record.infractions[key]) / route_length_kms
                     else:
                          global_record.infractions[key] += len(route_record.infractions[key]) / route_length_kms
 
                 if route_record.status is not 'Completed':
                     global_record.status = 'Failed'
                     if 'exceptions' not in global_record.meta:
                         global_record.meta['exceptions'] = []
                     global_record.meta['exceptions'].append((route_record.route_id,
                                                              route_record.index,
                                                              route_record.status))
 
             for key in global_record.scores.keys():
                 global_record.scores[key] /= float(total_routes)
             ...

In the line:
global_record.infractions[key] += len(route_record.infractions[key]) / route_length_kms

The infractions/km from all the individual routes simply get added together, leading to nonsense value that are dependent on the number of routes.
The current code implements the following formula:
image
where c_i is the number of collisions in route, km_i is the number of km driven in route i. N is the number of routes.

A naive fix would be to divide by the number of routes:
image
However this is not exactly the correct calculation.
Slicing the driven km into route segments changes the result of the infraction / km metric and in the worst case can lead to a simpsons paradox.

What we want to compute is the total number of collisions / total number of km driven so the correct formula is:
image

which in code would looks something like adding the infractions (per type) as well as adding the driven (!) km to variables outside the for_loop and after the route for loop dividing the counts by the total number of driven kms.

@Kin-Zhang
Copy link

leading to nonsense value that are dependent on the number of routes.
image

I knew what you mean here, but the infraction on global record may want to the result as the formula here.

The next one actually cannot seem like the average of collisions on routes kilometers. but average on all kilometers with fading the route concept?

image

But I agree with your opinion. since the first one will cause some number really big when the route_length_kms on one route are really small.

@Kait0
Copy link
Author

Kait0 commented May 16, 2022

The next one actually cannot seem like the average of collisions on routes kilometers. but average on all kilometers with fading the route concept?

Precisely, the concept of a route is not part of the infractions / km metrics.
If you look at the official descriptions on the leaderboard website, they say for example:
Collision Vehicles: "Number of collisions with other vehicles, normalized per km."

No route concept is mentioned there.
It is not a metric that averages (the routes) like for example the route completion which says:
Route completion: "Average percentage of routes completed."

@Kait0
Copy link
Author

Kait0 commented May 26, 2022

As a sidenote one needs to take additional care with the off-road infraction metric.
Right now I think the leaderboard always reports it as one infraction adding together the total amount of meters driven off road.
So counting does not work for that infraction since it is either 1 or 0.
With the current system one can sum up the (kilo!) meters driven off road (and divide by the total number of km driven) to get a meaningful estimate (maybe multiply by 100 because that is a percentage).

The other option would be to change how off-road is reported and report every single instance where the agent drove off the road (and then just count as usual).

@glopezdiest
Copy link
Contributor

Hey @Kait0, thanks for the detailed explanation. I'll take a look at it and report back

@glopezdiest
Copy link
Contributor

After some inspection, it does seem to be misscalculated. We are indeed using
image
to calculate the infractions per km, while in reality we want
image

I'll update the Leaderboard as soon as I can with this fix, thanks 🙂

@glopezdiest
Copy link
Contributor

With the coming release of the LB 2.0, this issue has been fixed. It is currently only available in the leaderboard-2.0 branch, but for those interested, the fix is done in this PR https://github.com/carla-simulator/leaderboard/pull/130/files (along with many other things).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants