MCPcopy Create free account
hub / github.com/dmlc/xgboost / GenerateRandomCategoricalSingleColumn

Function GenerateRandomCategoricalSingleColumn

tests/cpp/helpers.cc:617–628  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

615}
616
617[[nodiscard]] std::vector<float> GenerateRandomCategoricalSingleColumn(std::size_t n,
618 std::size_t n_categories) {
619 std::vector<float> x(n);
620 std::mt19937 rng(0);
621 std::uniform_int_distribution<size_t> dist(0, n_categories - 1);
622 std::generate(x.begin(), x.end(), [&]() { return static_cast<float>(dist(rng)); });
623 // Make sure each category is present
624 for (size_t i = 0; i < n_categories; i++) {
625 x[i] = static_cast<decltype(x)::value_type>(i);
626 }
627 return x;
628}
629
630std::shared_ptr<DMatrix> GetDMatrixFromData(const std::vector<float>& x, std::size_t num_rows,
631 bst_feature_t num_columns) {

Callers 2

TESTFunction · 0.85
TestHistogramCategoricalFunction · 0.85

Calls 2

beginMethod · 0.45
endMethod · 0.45

Tested by 2

TESTFunction · 0.68
TestHistogramCategoricalFunction · 0.68