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 <vector>
12 #include <string>
13 #include <functional>
14 #include <utility>
15 
16 #include "./data.h"
17 #include "./base.h"
18 #include "../../src/common/host_device_vector.h"
19 
20 namespace xgboost {
25 class Metric {
26  public:
31  virtual void Configure(
32  const std::vector<std::pair<std::string, std::string> >& args) {}
39  template<typename PairIter>
40  inline void Configure(PairIter begin, PairIter end) {
41  std::vector<std::pair<std::string, std::string> > vec(begin, end);
42  this->Configure(vec);
43  }
52  virtual bst_float Eval(const HostDeviceVector<bst_float>& preds,
53  const MetaInfo& info,
54  bool distributed) = 0;
56  virtual const char* Name() const = 0;
58  virtual ~Metric() = default;
66  static Metric* Create(const std::string& name);
67 };
68 
74 struct MetricReg
75  : public dmlc::FunctionRegEntryBase<MetricReg,
76  std::function<Metric* (const char*)> > {
77 };
78 
92 #define XGBOOST_REGISTER_METRIC(UniqueId, Name) \
93  ::xgboost::MetricReg& __make_ ## MetricReg ## _ ## UniqueId ## __ = \
94  ::dmlc::Registry< ::xgboost::MetricReg>::Get()->__REGISTER__(Name)
95 } // namespace xgboost
96 #endif // XGBOOST_METRIC_H_
Registry entry for Metric factory functions. The additional parameter const char* param gives the val...
Definition: metric.h:74
float bst_float
float type, used for storing statistics
Definition: base.h:89
virtual void Configure(const std::vector< std::pair< std::string, std::string > > &args)
Configure the Metric with the specified parameters.
Definition: metric.h:31
static Metric * Create(const std::string &name)
create a metric according to name.
Meta information about dataset, always sit in memory.
Definition: data.h:40
void Configure(PairIter begin, PairIter end)
set configuration from pair iterators.
Definition: metric.h:40
The input data structure of xgboost.
virtual const char * Name() const =0
namespace of xgboost
Definition: base.h:79
defines configuration macros of xgboost.
virtual ~Metric()=default
virtual destructor
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:25