Debian Codegraph @

src/include/xgboost/linear_updater.h

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