-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
/
linear_updater.h
79 lines (66 loc) · 2.15 KB
/
linear_updater.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* Copyright 2018 by Contributors
*/
#pragma once
#include <dmlc/registry.h>
#include <xgboost/base.h>
#include <xgboost/data.h>
#include <xgboost/generic_parameters.h>
#include <xgboost/host_device_vector.h>
#include <xgboost/model.h>
#include <functional>
#include <string>
#include <utility>
#include <vector>
namespace xgboost {
class Json;
namespace gbm {
class GBLinearModel;
} // namespace gbm
/*!
* \brief interface of linear updater
*/
class LinearUpdater : public Configurable {
protected:
GenericParameter const* ctx_;
public:
/*! \brief virtual destructor */
~LinearUpdater() override = default;
/*!
* \brief Initialize the updater with given arguments.
* \param args arguments to the objective function.
*/
virtual void Configure(
const std::vector<std::pair<std::string, std::string> >& args) = 0;
/**
* \brief Updates linear model given gradients.
*
* \param in_gpair The gradient pair statistics of the data.
* \param data Input data matrix.
* \param model Model to be updated.
* \param sum_instance_weight The sum instance weights, used to normalise l1/l2 penalty.
*/
virtual void Update(HostDeviceVector<GradientPair>* in_gpair, DMatrix* data,
gbm::GBLinearModel* model,
double sum_instance_weight) = 0;
/*!
* \brief Create a linear updater given name
* \param name Name of the linear updater.
*/
static LinearUpdater* Create(const std::string& name, GenericParameter const*);
};
/*!
* \brief Registry entry for linear updater.
*/
struct LinearUpdaterReg
: public dmlc::FunctionRegEntryBase<LinearUpdaterReg,
std::function<LinearUpdater*()> > {};
/*!
* \brief Macro to register linear updater.
*/
#define XGBOOST_REGISTER_LINEAR_UPDATER(UniqueId, Name) \
static DMLC_ATTRIBUTE_UNUSED ::xgboost::LinearUpdaterReg& \
__make_##LinearUpdaterReg##_##UniqueId##__ = \
::dmlc::Registry< ::xgboost::LinearUpdaterReg>::Get()->__REGISTER__( \
Name)
} // namespace xgboost