xgboost

objective.h
Go to the documentation of this file.
1
7 #ifndef XGBOOST_OBJECTIVE_H_
8 #define XGBOOST_OBJECTIVE_H_
9
10 #include <dmlc/registry.h>
11 #include <xgboost/base.h>
12 #include <xgboost/data.h>
13 #include <xgboost/model.h>
14 #include <xgboost/generic_parameters.h>
15 #include <xgboost/host_device_vector.h>
16
17 #include <vector>
18 #include <utility>
19 #include <string>
20 #include <functional>
21
22 namespace xgboost {
23
25 class ObjFunction : public Configurable {
26 protected:
27 GenericParameter const* tparam_;
28
29 public:
31 ~ObjFunction() override = default;
36 virtual void Configure(const std::vector<std::pair<std::string, std::string> >& args) = 0;
44 virtual void GetGradient(const HostDeviceVector<bst_float>& preds,
45 const MetaInfo& info,
46 int iteration,
47 HostDeviceVector<GradientPair>* out_gpair) = 0;
48
50 virtual const char* DefaultEvalMetric() const = 0;
51 // the following functions are optional, most of time default implementation is good enough
56 virtual void PredTransform(HostDeviceVector<bst_float> *io_preds) {}
57
63 virtual void EvalTransform(HostDeviceVector<bst_float> *io_preds) {
64 this->PredTransform(io_preds);
65 }
72 virtual bst_float ProbToMargin(bst_float base_score) const {
73 return base_score;
74 }
80 static ObjFunction* Create(const std::string& name, GenericParameter const* tparam);
81 };
82
86 struct ObjFunctionReg
87 : public dmlc::FunctionRegEntryBase<ObjFunctionReg,
88 std::function<ObjFunction* ()> > {
89 };
90
103 #define XGBOOST_REGISTER_OBJECTIVE(UniqueId, Name) \
104 static DMLC_ATTRIBUTE_UNUSED ::xgboost::ObjFunctionReg & \
105 __make_ ## ObjFunctionReg ## _ ## UniqueId ## __ = \
106 ::dmlc::Registry< ::xgboost::ObjFunctionReg>::Get()->__REGISTER__(Name)
107 } // namespace xgboost
108 #endif // XGBOOST_OBJECTIVE_H_
xgboost::ObjFunction::GetGradient
virtual void GetGradient(const HostDeviceVector< bst_float > &preds, const MetaInfo &info, int iteration, HostDeviceVector< GradientPair > *out_gpair)=0
Get gradient over each of predictions, given existing information.
xgboost::ObjFunction::Configure
virtual void Configure(const std::vector< std::pair< std::string, std::string > > &args)=0
Configure the objective with the specified parameters.
xgboost::bst_float
float bst_float
float type, used for storing statistics
Definition: base.h:111
xgboost::MetaInfo
Meta information about dataset, always sit in memory.
Definition: data.h:45
xgboost::HostDeviceVector< bst_float >
xgboost::ObjFunction::~ObjFunction
~ObjFunction() override=default
virtual destructor
data.h
The input data structure of xgboost.
xgboost::GenericParameter
Definition: generic_parameters.h:14
model.h
Defines the abstract interface for different components in XGBoost.
host_device_vector.h
A device-and-host vector abstraction layer.
xgboost::ObjFunctionReg
Registry entry for objective factory functions.
Definition: objective.h:86
xgboost::ObjFunction::DefaultEvalMetric
virtual const char * DefaultEvalMetric() const =0
xgboost::ObjFunction::EvalTransform
virtual void EvalTransform(HostDeviceVector< bst_float > *io_preds)
transform prediction values, this is only called when Eval is called, usually it redirect to PredTran...
Definition: objective.h:63
xgboost::Configurable
Definition: model.h:31
xgboost::ObjFunction
interface of objective function
Definition: objective.h:25
xgboost::ObjFunction::ProbToMargin
virtual bst_float ProbToMargin(bst_float base_score) const
transform probability value back to margin this is used to transform user-set base_score back to marg...
Definition: objective.h:72
xgboost
namespace of xgboost
Definition: base.h:102
base.h
defines configuration macros of xgboost.
generic_parameters.h
xgboost::ObjFunction::Create
static ObjFunction * Create(const std::string &name, GenericParameter const *tparam)
Create an objective function according to name.
xgboost::ObjFunction::PredTransform
virtual void PredTransform(HostDeviceVector< bst_float > *io_preds)
transform prediction values, this is only called when Prediction is called
Definition: objective.h:56
xgboost::ObjFunction::tparam_
GenericParameter const * tparam_
Definition: objective.h:27