xgboost
metric.h
Go to the documentation of this file.
1 
7 #ifndef XGBOOST_METRIC_H_
8 #define XGBOOST_METRIC_H_
9 
10 #include <dmlc/registry.h>
11 #include <xgboost/model.h>
13 #include <xgboost/data.h>
14 #include <xgboost/base.h>
16 
17 #include <vector>
18 #include <string>
19 #include <functional>
20 #include <utility>
21 
22 namespace xgboost {
27 class Metric : public Configurable {
28  protected:
30 
31  public:
36  virtual void Configure(
37  const std::vector<std::pair<std::string, std::string> >& args) {}
44  void LoadConfig(Json const& in) override {}
51  void SaveConfig(Json* out) const override {}
52 
61  virtual bst_float Eval(const HostDeviceVector<bst_float>& preds,
62  const MetaInfo& info,
63  bool distributed) = 0;
65  virtual const char* Name() const = 0;
67  ~Metric() override = default;
76  static Metric* Create(const std::string& name, GenericParameter const* tparam);
77 };
78 
84 struct MetricReg
85  : public dmlc::FunctionRegEntryBase<MetricReg,
86  std::function<Metric* (const char*)> > {
87 };
88 
102 #define XGBOOST_REGISTER_METRIC(UniqueId, Name) \
103  ::xgboost::MetricReg& __make_ ## MetricReg ## _ ## UniqueId ## __ = \
104  ::dmlc::Registry< ::xgboost::MetricReg>::Get()->__REGISTER__(Name)
105 } // namespace xgboost
106 #endif // XGBOOST_METRIC_H_
Registry entry for Metric factory functions. The additional parameter const char* param gives the val...
Definition: metric.h:84
float bst_float
float type, used for storing statistics
Definition: base.h:111
virtual void Configure(const std::vector< std::pair< std::string, std::string > > &args)
Configure the Metric with the specified parameters.
Definition: metric.h:36
static Metric * Create(const std::string &name, GenericParameter const *tparam)
create a metric according to name.
Meta information about dataset, always sit in memory.
Definition: data.h:45
~Metric() override=default
virtual destructor
The input data structure of xgboost.
Definition: generic_parameters.h:14
Defines the abstract interface for different components in XGBoost.
A device-and-host vector abstraction layer.
virtual const char * Name() const =0
Definition: model.h:31
namespace of xgboost
Definition: base.h:102
defines configuration macros of xgboost.
GenericParameter const * tparam_
Definition: metric.h:29
virtual bst_float Eval(const HostDeviceVector< bst_float > &preds, const MetaInfo &info, bool distributed)=0
evaluate a specific metric
interface of evaluation metric used to evaluate model performance. This has nothing to do with traini...
Definition: metric.h:27
Data structure representing JSON format.
Definition: json.h:326
void SaveConfig(Json *out) const override
Save configuration to JSON object By default, metric has no internal configuration; override this fun...
Definition: metric.h:51
void LoadConfig(Json const &in) override
Load configuration from JSON object By default, metric has no internal configuration; override this f...
Definition: metric.h:44