| 1 | /** |
| 2 | * Copyright 2021-2024, XGBoost Contributors |
| 3 | */ |
| 4 | #ifndef XGBOOST_TASK_H_ |
| 5 | #define XGBOOST_TASK_H_ |
| 6 | |
| 7 | #include <xgboost/base.h> |
| 8 | |
| 9 | #include <cstdint> // for uint8_t |
| 10 | |
| 11 | namespace xgboost { |
| 12 | /*! |
| 13 | * \brief A struct returned by objective, which determines task at hand. The struct is |
| 14 | * not used by any algorithm yet, only for future development like categorical |
| 15 | * split. |
| 16 | * |
| 17 | * The task field is useful for tree split finding, also for some metrics like auc. |
| 18 | * Lastly, knowing whether hessian is constant can allow some optimizations like skipping |
| 19 | * the quantile sketching. |
| 20 | * |
| 21 | * This struct should not be serialized since it can be recovered from objective function, |
| 22 | * hence it doesn't need to be stable. |
| 23 | */ |
| 24 | struct ObjInfo { |
| 25 | // What kind of problem are we trying to solve |
| 26 | enum Task : std::uint8_t { |
| 27 | kRegression = 0, |
| 28 | kBinary = 1, |
| 29 | kClassification = 2, |
| 30 | kSurvival = 3, |
| 31 | kRanking = 4, |
| 32 | kOther = 5, |
| 33 | } task; |
| 34 | // Does the objective have constant hessian value? |
| 35 | bool const_hess{false}; |
| 36 | bool zero_hess{false}; |
| 37 | |
| 38 | ObjInfo(Task t) : task{t} {} // NOLINT |
| 39 | ObjInfo(Task t, bool khess, bool zhess) : task{t}, const_hess{khess}, zero_hess(zhess) {} |
| 40 | |
| 41 | /** |
| 42 | * \brief Use adaptive tree if the objective doesn't have valid hessian value. |
| 43 | */ |
| 44 | XGBOOST_DEVICE bool UpdateTreeLeaf() const { return zero_hess; } |
| 45 | }; |
| 46 | } // namespace xgboost |
| 47 | #endif // XGBOOST_TASK_H_ |