Medial Code Documentation
Loading...
Searching...
No Matches
quantile_loss_utils.h
1
4#ifndef XGBOOST_COMMON_QUANTILE_LOSS_UTILS_H_
5#define XGBOOST_COMMON_QUANTILE_LOSS_UTILS_H_
6
7#include <algorithm> // std::all_of
8#include <istream> // std::istream
9#include <ostream> // std::ostream
10#include <vector> // std::vector
11
12#include "xgboost/logging.h" // CHECK
13#include "xgboost/parameter.h" // XGBoostParameter
14
15namespace xgboost {
16namespace common {
17// A shim to enable ADL for parameter parsing. Alternatively, we can put the stream
18// operators in std namespace, which seems to be less ideal.
20 std::vector<float> values_;
21
22 public:
23 std::vector<float>& Get() { return values_; }
24 std::vector<float> const& Get() const { return values_; }
25 decltype(values_)::const_reference operator[](decltype(values_)::size_type i) const {
26 return values_[i];
27 }
28};
29
30// For parsing quantile parameters. Input can be a string to a single float or a list of
31// floats.
32std::ostream& operator<<(std::ostream& os, const ParamFloatArray& t);
33std::istream& operator>>(std::istream& is, ParamFloatArray& t);
34
35struct QuantileLossParam : public XGBoostParameter<QuantileLossParam> {
36 ParamFloatArray quantile_alpha;
37 DMLC_DECLARE_PARAMETER(QuantileLossParam) {
38 DMLC_DECLARE_FIELD(quantile_alpha).describe("List of quantiles for quantile loss.");
39 }
40 void Validate() const {
41 CHECK(GetInitialised());
42 CHECK(!quantile_alpha.Get().empty());
43 auto const& array = quantile_alpha.Get();
44 auto valid =
45 std::all_of(array.cbegin(), array.cend(), [](auto q) { return q >= 0.0 && q <= 1.0; });
46 CHECK(valid) << "quantile alpha must be in the range [0.0, 1.0].";
47 }
48};
49} // namespace common
50} // namespace xgboost
51#endif // XGBOOST_COMMON_QUANTILE_LOSS_UTILS_H_
Definition quantile_loss_utils.h:19
defines console logging options for xgboost. Use to enforce unified print behavior.
macro for using C++11 enum class as DMLC parameter
namespace of xgboost
Definition base.h:90
Definition parameter.h:84
Definition quantile_loss_utils.h:35