Skip to content

Commit

Permalink
Ensure quantile forests give consistent estimates across platforms. (g…
Browse files Browse the repository at this point in the history
…rf-labs#492)

We now include a tie-breaker while sorting the list of sample IDs and outcomes.
Without the tie-breaker, the sort could produce a different element ordering
across different runs of the algorithm.
  • Loading branch information
jtibshirani authored and davidahirshberg committed Dec 6, 2019
1 parent 477f24b commit 72e01de
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
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

0 comments on commit 72e01de

Please sign in to comment.