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>
12 #include <xgboost/generic_parameters.h>
13 #include <xgboost/data.h>
14 #include <xgboost/base.h>
15 #include <xgboost/host_device_vector.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:
29 GenericParameter const* tparam_;
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*) 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_
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:84
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::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::SaveConfig
void SaveConfig(Json *) const override
Save configuration to JSON object By default, metric has no internal configuration; override this fun...
Definition: metric.h:51
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
data.h
The input data structure of xgboost.
xgboost::MetaInfo
Meta information about dataset, always sit in memory.
Definition: data.h:45
xgboost::Json
Data structure representing JSON format.
Definition: json.h:345
xgboost::Metric
interface of evaluation metric used to evaluate model performance. This has nothing to do with traini...
Definition: metric.h:27
xgboost::Metric::Eval
virtual bst_float Eval(const HostDeviceVector< bst_float > &preds, const MetaInfo &info, bool distributed)=0
evaluate a specific metric
xgboost
namespace of xgboost
Definition: base.h:110
xgboost::bst_float
float bst_float
float type, used for storing statistics
Definition: base.h:119