Jiaming Yuan fdf533f2b9
[POC] Experimental support for l1 error. (#7812)
Support adaptive tree, a feature supported by both sklearn and lightgbm.  The tree leaf is recomputed based on residue of labels and predictions after construction.

For l1 error, the optimal value is the median (50 percentile).

This is marked as experimental support for the following reasons:
- The value is not well defined for distributed training, where we might have empty leaves for local workers. Right now I just use the original leaf value for computing the average with other workers, which might cause significant errors.
- Some follow-ups are required, for exact, pruner, and optimization for quantile function. Also, we need to calculate the initial estimation.
2022-04-26 21:41:55 +08:00

51 lines
1.5 KiB
C++

/*!
* Copyright 2021-2022 by XGBoost Contributors
*/
#ifndef XGBOOST_TASK_H_
#define XGBOOST_TASK_H_
#include <xgboost/base.h>
#include <cinttypes>
namespace xgboost {
/*!
* \brief A struct returned by objective, which determines task at hand. The struct is
* not used by any algorithm yet, only for future development like categorical
* split.
*
* The task field is useful for tree split finding, also for some metrics like auc.
* Lastly, knowing whether hessian is constant can allow some optimizations like skipping
* the quantile sketching.
*
* This struct should not be serialized since it can be recovered from objective function,
* hence it doesn't need to be stable.
*/
struct ObjInfo {
// What kind of problem are we trying to solve
enum Task : uint8_t {
kRegression = 0,
kBinary = 1,
kClassification = 2,
kSurvival = 3,
kRanking = 4,
kOther = 5,
} task;
// Does the objective have constant hessian value?
bool const_hess{false};
bool zero_hess{false};
ObjInfo(Task t) : task{t} {} // NOLINT
ObjInfo(Task t, bool khess, bool zhess) : task{t}, const_hess{khess}, zero_hess(zhess) {}
XGBOOST_DEVICE bool UseOneHot() const {
return (task != ObjInfo::kRegression && task != ObjInfo::kBinary);
}
/**
* \brief Use adaptive tree if the objective doesn't have valid hessian value.
*/
XGBOOST_DEVICE bool UpdateTreeLeaf() const { return zero_hess; }
};
} // namespace xgboost
#endif // XGBOOST_TASK_H_