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> >&) {}
44  void LoadConfig(Json const&) override {}
51  void SaveConfig(Json* p_out) const override {
52  auto& out = *p_out;
53  out["name"] = String(this->Name());
54  }
55 
64  virtual double Eval(const HostDeviceVector<bst_float> &preds,
65  const MetaInfo &info, bool distributed) = 0;
67  virtual const char* Name() const = 0;
69  ~Metric() override = default;
78  static Metric* Create(const std::string& name, GenericParameter const* tparam);
79 };
80 
86 struct MetricReg
87  : public dmlc::FunctionRegEntryBase<MetricReg,
88  std::function<Metric* (const char*)> > {
89 };
90 
104 #define XGBOOST_REGISTER_METRIC(UniqueId, Name) \
105  ::xgboost::MetricReg& __make_ ## MetricReg ## _ ## UniqueId ## __ = \
106  ::dmlc::Registry< ::xgboost::MetricReg>::Get()->__REGISTER__(Name)
107 } // namespace xgboost
108 #endif // XGBOOST_METRIC_H_
xgboost::Metric::~Metric
~Metric() override=default
virtual destructor
xgboost::Metric::Create
static Metric * Create(const std::string &name, GenericParameter const *tparam)
create a metric according to name.
model.h
Defines the abstract interface for different components in XGBoost.
xgboost::GenericParameter
Definition: generic_parameters.h:15
xgboost::HostDeviceVector< bst_float >
host_device_vector.h
A device-and-host vector abstraction layer.
xgboost::MetricReg
Registry entry for Metric factory functions. The additional parameter const char* param gives the val...
Definition: metric.h:86
base.h
defines configuration macros of xgboost.
xgboost::Metric::Configure
virtual void Configure(const std::vector< std::pair< std::string, std::string > > &)
Configure the Metric with the specified parameters.
Definition: metric.h:36
xgboost::Metric::SaveConfig
void SaveConfig(Json *p_out) const override
Save configuration to JSON object By default, metric has no internal configuration; override this fun...
Definition: metric.h:51
xgboost::Metric::LoadConfig
void LoadConfig(Json const &) override
Load configuration from JSON object By default, metric has no internal configuration; override this f...
Definition: metric.h:44
xgboost::Metric::Name
virtual const char * Name() const =0
xgboost::Metric::tparam_
GenericParameter const * tparam_
Definition: metric.h:29
xgboost::Configurable
Definition: model.h:31
generic_parameters.h
xgboost::String
JsonString String
Definition: json.h:593
data.h
The input data structure of xgboost.
xgboost::MetaInfo
Meta information about dataset, always sit in memory.
Definition: data.h:46
xgboost::Json
Data structure representing JSON format.
Definition: json.h:352
xgboost::Metric::Eval
virtual double Eval(const HostDeviceVector< bst_float > &preds, const MetaInfo &info, bool distributed)=0
evaluate a specific metric
xgboost::Metric
interface of evaluation metric used to evaluate model performance. This has nothing to do with traini...
Definition: metric.h:27
xgboost
namespace of xgboost
Definition: base.h:110