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 <vector>
12 #include <utility>
13 #include <string>
14 #include <functional>
15 #include "./data.h"
16 #include "./base.h"
17 #include "../../src/common/host_device_vector.h"
18 
19 
20 namespace xgboost {
21 
23 class ObjFunction {
24  public:
26  virtual ~ObjFunction() = default;
33  template<typename PairIter>
34  inline void Configure(PairIter begin, PairIter end);
39  virtual void Configure(const std::vector<std::pair<std::string, std::string> >& args) = 0;
47  virtual void GetGradient(const HostDeviceVector<bst_float>& preds,
48  const MetaInfo& info,
49  int iteration,
50  HostDeviceVector<GradientPair>* out_gpair) = 0;
51 
53  virtual const char* DefaultEvalMetric() const = 0;
54  // the following functions are optional, most of time default implementation is good enough
59  virtual void PredTransform(HostDeviceVector<bst_float> *io_preds) {}
60 
66  virtual void EvalTransform(HostDeviceVector<bst_float> *io_preds) {
67  this->PredTransform(io_preds);
68  }
75  virtual bst_float ProbToMargin(bst_float base_score) const {
76  return base_score;
77  }
82  static ObjFunction* Create(const std::string& name);
83 };
84 
85 // implementing configure.
86 template<typename PairIter>
87 inline void ObjFunction::Configure(PairIter begin, PairIter end) {
88  std::vector<std::pair<std::string, std::string> > vec(begin, end);
89  this->Configure(vec);
90 }
91 
96  : public dmlc::FunctionRegEntryBase<ObjFunctionReg,
97  std::function<ObjFunction* ()> > {
98 };
99 
112 #define XGBOOST_REGISTER_OBJECTIVE(UniqueId, Name) \
113  static DMLC_ATTRIBUTE_UNUSED ::xgboost::ObjFunctionReg & \
114  __make_ ## ObjFunctionReg ## _ ## UniqueId ## __ = \
115  ::dmlc::Registry< ::xgboost::ObjFunctionReg>::Get()->__REGISTER__(Name)
116 } // namespace xgboost
117 #endif // XGBOOST_OBJECTIVE_H_
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.
float bst_float
float type, used for storing statistics
Definition: base.h:89
Meta information about dataset, always sit in memory.
Definition: data.h:40
static ObjFunction * Create(const std::string &name)
Create an objective function according to name.
The input data structure of xgboost.
Registry entry for objective factory functions.
Definition: objective.h:95
virtual const char * DefaultEvalMetric() const =0
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:66
interface of objective function
Definition: objective.h:23
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:75
namespace of xgboost
Definition: base.h:79
defines configuration macros of xgboost.
void Configure(PairIter begin, PairIter end)
set configuration from pair iterators.
Definition: objective.h:87
virtual void PredTransform(HostDeviceVector< bst_float > *io_preds)
transform prediction values, this is only called when Prediction is called
Definition: objective.h:59
virtual ~ObjFunction()=default
virtual destructor