Medial Code Documentation
Loading...
Searching...
No Matches
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/base.h>
12#include <xgboost/data.h>
14#include <xgboost/model.h>
15
16#include <functional>
17#include <memory> // shared_ptr
18#include <string>
19#include <utility>
20#include <vector>
21
22namespace xgboost {
23struct Context;
24
29class Metric : public Configurable {
30 protected:
31 Context const* ctx_{nullptr};
32
33 public:
38 virtual void Configure(
39 const std::vector<std::pair<std::string, std::string> >&) {}
46 void LoadConfig(Json const&) override {}
53 void SaveConfig(Json* p_out) const override {
54 auto& out = *p_out;
55 out["name"] = String(this->Name());
56 }
57
64 virtual double Evaluate(HostDeviceVector<bst_float> const& preds,
65 std::shared_ptr<DMatrix> p_fmat) = 0;
66
68 virtual const char* Name() const = 0;
70 ~Metric() override = default;
79 static Metric* Create(const std::string& name, Context const* ctx);
80};
81
88 : public dmlc::FunctionRegEntryBase<MetricReg,
89 std::function<Metric* (const char*)> > {
90};
91
105#define XGBOOST_REGISTER_METRIC(UniqueId, Name) \
106 ::xgboost::MetricReg& __make_ ## MetricReg ## _ ## UniqueId ## __ = \
107 ::dmlc::Registry< ::xgboost::MetricReg>::Get()->__REGISTER__(Name)
108} // namespace xgboost
109#endif // XGBOOST_METRIC_H_
Common base class for function registry.
Definition registry.h:151
Definition host_device_vector.h:87
Definition json.h:87
Data structure representing JSON format.
Definition json.h:357
interface of evaluation metric used to evaluate model performance. This has nothing to do with traini...
Definition metric.h:29
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:53
static Metric * Create(const std::string &name, Context const *ctx)
create a metric according to name.
Definition metric.cc:46
virtual void Configure(const std::vector< std::pair< std::string, std::string > > &)
Configure the Metric with the specified parameters.
Definition metric.h:38
void LoadConfig(Json const &) override
Load configuration from JSON object By default, metric has no internal configuration; override this f...
Definition metric.h:46
virtual const char * Name() const =0
~Metric() override=default
virtual destructor
virtual double Evaluate(HostDeviceVector< bst_float > const &preds, std::shared_ptr< DMatrix > p_fmat)=0
Evaluate a metric with DMatrix as input.
A device-and-host vector abstraction layer.
Copyright 2015-2023 by XGBoost Contributors.
Copyright 2015-2023 by XGBoost Contributors.
Defines the abstract interface for different components in XGBoost.
namespace of xgboost
Definition base.h:90
Registry utility that helps to build registry singletons.
Definition model.h:31
Runtime context for XGBoost.
Definition context.h:84
Registry entry for Metric factory functions. The additional parameter const char* param gives the val...
Definition metric.h:89