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

Ensure quantile forests give consistent estimates across platforms. #492

Merged
merged 1 commit into from
Aug 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion core/src/prediction/QuantilePredictionStrategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ std::vector<double> QuantilePredictionStrategy::compute_quantile_cutoffs(
std::sort(samples_and_values.begin(),
samples_and_values.end(),
[](std::pair<size_t, double> first_pair, std::pair<size_t, double> second_pair) {
return first_pair.second < second_pair.second;
// Note: we add a tie-breaker here to ensure that this sort consistently produces the
// same element ordering. Otherwise, different runs of the algorithm could result in
// different quantile predictions on the same data.
return first_pair.second < second_pair.second
|| (first_pair.second == second_pair.second && first_pair.first < second_pair.first);
});

std::vector<double> quantile_cutoffs;
Expand Down
18 changes: 9 additions & 9 deletions core/test/forest/resources/quantile_oob_predictions.csv
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
-10, -10, 10
-10, -10, 10
-1, -1, 1
-1, -1, 1
-1, 1, 1
-1, -1, 1
10, 10, 10
-10, -10, -10
Expand Down Expand Up @@ -410,7 +410,7 @@
-1, -1, 1
-1, -1, 1
-1, -1, 1
-10, -10, 10
-10, 10, 10
-1, -1, 1
10, 10, 10
-1, -1, 1
Expand All @@ -421,7 +421,7 @@
-10, 10, 10
-1, -1, 1
-1, -1, 1
-1, -1, 1
-1, 1, 1
-1, -1, 1
-1, 1, 1
-10, 10, 10
Expand Down Expand Up @@ -459,7 +459,7 @@
-1, -1, 1
-10, 10, 10
-10, -10, 10
-10, 10, 10
-10, -10, 10
-1, -1, 1
-1, -1, 1
-10, -1, 10
Expand Down Expand Up @@ -537,7 +537,7 @@
-10, 10, 10
-1, 1, 1
-1, -1, 1
-10, 10, 10
-10, -10, 10
-10, -10, 10
-1, 1, 1
-1, 1, 1
Expand Down Expand Up @@ -589,7 +589,7 @@
-1, 1, 1
-1, -1, 1
-10, 10, 10
-1, -1, 1
-1, 1, 1
-1, 1, 1
-1, -1, 1
-10, -10, 10
Expand Down Expand Up @@ -832,7 +832,7 @@
-10, -10, 10
-1, 1, 1
-10, -10, -10
-1, 1, 1
-1, -1, 1
-1, 1, 1
-1, -1, 1
-10, -10, 10
Expand All @@ -847,7 +847,7 @@
-1, -1, 1
-1, -1, 1
-1, -1, 1
-10, -10, 10
-10, 10, 10
-10, -10, 10
-10, 10, 10
-1, -1, 1
Expand All @@ -857,7 +857,7 @@
10, 10, 10
-10, -10, 1
-10, 10, 10
-10, -1, 10
-10, -10, 10
-1, -1, -1
-1, 1, 1
-1, 1, 1
Expand Down