* Refactor configuration [Part II].
* General changes:
** Remove `Init` methods to avoid ambiguity.
** Remove `Configure(std::map<>)` to avoid redundant copying and prepare for
parameter validation. (`std::vector` is returned from `InitAllowUnknown`).
** Add name to tree updaters for easier debugging.
* Learner changes:
** Make `LearnerImpl` the only source of configuration.
All configurations are stored and carried out by `LearnerImpl::Configure()`.
** Remove booster in C API.
Originally kept for "compatibility reason", but did not state why. So here
we just remove it.
** Add a `metric_names_` field in `LearnerImpl`.
** Remove `LazyInit`. Configuration will always be lazy.
** Run `Configure` before every iteration.
* Predictor changes:
** Allocate both cpu and gpu predictor.
** Remove cpu_predictor from gpu_predictor.
`GBTree` is now used to dispatch the predictor.
** Remove some GPU Predictor tests.
* IO
No IO changes. The binary model format stability is tested by comparing
hashing value of save models between two commits
71 lines
2.1 KiB
C++
71 lines
2.1 KiB
C++
/*
|
|
* Copyright 2018 by Contributors
|
|
*/
|
|
#pragma once
|
|
|
|
#include <dmlc/registry.h>
|
|
#include <xgboost/base.h>
|
|
#include <xgboost/data.h>
|
|
#include <xgboost/generic_parameters.h>
|
|
#include <functional>
|
|
#include <string>
|
|
#include <utility>
|
|
#include <vector>
|
|
#include "../../src/gbm/gblinear_model.h"
|
|
#include "../../src/common/host_device_vector.h"
|
|
|
|
namespace xgboost {
|
|
/*!
|
|
* \brief interface of linear updater
|
|
*/
|
|
class LinearUpdater {
|
|
protected:
|
|
GenericParameter const* learner_param_;
|
|
|
|
public:
|
|
/*! \brief virtual destructor */
|
|
virtual ~LinearUpdater() = 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
|