Initial support for quantile loss. (#8750)
- Add support for Python. - Add objective.
This commit is contained in:
@@ -11,19 +11,20 @@
|
||||
namespace xgboost {
|
||||
namespace common {
|
||||
TEST(Stats, Quantile) {
|
||||
Context ctx;
|
||||
{
|
||||
linalg::Tensor<float, 1> arr({20.f, 0.f, 15.f, 50.f, 40.f, 0.f, 35.f}, {7}, Context::kCpuId);
|
||||
std::vector<size_t> index{0, 2, 3, 4, 6};
|
||||
auto h_arr = arr.HostView();
|
||||
auto beg = MakeIndexTransformIter([&](size_t i) { return h_arr(index[i]); });
|
||||
auto end = beg + index.size();
|
||||
auto q = Quantile(0.40f, beg, end);
|
||||
auto q = Quantile(&ctx, 0.40f, beg, end);
|
||||
ASSERT_EQ(q, 26.0);
|
||||
|
||||
q = Quantile(0.20f, beg, end);
|
||||
q = Quantile(&ctx, 0.20f, beg, end);
|
||||
ASSERT_EQ(q, 16.0);
|
||||
|
||||
q = Quantile(0.10f, beg, end);
|
||||
q = Quantile(&ctx, 0.10f, beg, end);
|
||||
ASSERT_EQ(q, 15.0);
|
||||
}
|
||||
|
||||
@@ -31,12 +32,13 @@ TEST(Stats, Quantile) {
|
||||
std::vector<float> vec{1., 2., 3., 4., 5.};
|
||||
auto beg = MakeIndexTransformIter([&](size_t i) { return vec[i]; });
|
||||
auto end = beg + vec.size();
|
||||
auto q = Quantile(0.5f, beg, end);
|
||||
auto q = Quantile(&ctx, 0.5f, beg, end);
|
||||
ASSERT_EQ(q, 3.);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Stats, WeightedQuantile) {
|
||||
Context ctx;
|
||||
linalg::Tensor<float, 1> arr({1.f, 2.f, 3.f, 4.f, 5.f}, {5}, Context::kCpuId);
|
||||
linalg::Tensor<float, 1> weight({1.f, 1.f, 1.f, 1.f, 1.f}, {5}, Context::kCpuId);
|
||||
|
||||
@@ -47,13 +49,13 @@ TEST(Stats, WeightedQuantile) {
|
||||
auto end = beg + arr.Size();
|
||||
auto w = MakeIndexTransformIter([&](size_t i) { return h_weight(i); });
|
||||
|
||||
auto q = WeightedQuantile(0.50f, beg, end, w);
|
||||
auto q = WeightedQuantile(&ctx, 0.50f, beg, end, w);
|
||||
ASSERT_EQ(q, 3);
|
||||
|
||||
q = WeightedQuantile(0.0, beg, end, w);
|
||||
q = WeightedQuantile(&ctx, 0.0, beg, end, w);
|
||||
ASSERT_EQ(q, 1);
|
||||
|
||||
q = WeightedQuantile(1.0, beg, end, w);
|
||||
q = WeightedQuantile(&ctx, 1.0, beg, end, w);
|
||||
ASSERT_EQ(q, 5);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user