diff --git a/core/src/prediction/QuantilePredictionStrategy.cpp b/core/src/prediction/QuantilePredictionStrategy.cpp index 511126495..d9556bb90 100644 --- a/core/src/prediction/QuantilePredictionStrategy.cpp +++ b/core/src/prediction/QuantilePredictionStrategy.cpp @@ -52,7 +52,11 @@ std::vector QuantilePredictionStrategy::compute_quantile_cutoffs( std::sort(samples_and_values.begin(), samples_and_values.end(), [](std::pair first_pair, std::pair 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 quantile_cutoffs; diff --git a/core/test/forest/resources/quantile_oob_predictions.csv b/core/test/forest/resources/quantile_oob_predictions.csv index da10cfe6b..534c7d97f 100644 --- a/core/test/forest/resources/quantile_oob_predictions.csv +++ b/core/test/forest/resources/quantile_oob_predictions.csv @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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