[TREE] Enable updater registry
This commit is contained in:
@@ -1,13 +0,0 @@
|
||||
/*!
|
||||
* Copyright 2014 by Contributors
|
||||
* \file sync.h
|
||||
* \brief the synchronization module of rabit
|
||||
* redirects to rabit header
|
||||
* \author Tianqi Chen
|
||||
*/
|
||||
#ifndef XGBOOST_SYNC_H_
|
||||
#define XGBOOST_SYNC_H_
|
||||
|
||||
#include <rabit.h>
|
||||
|
||||
#endif // XGBOOST_SYNC_H_
|
||||
@@ -332,8 +332,8 @@ class TreeModel {
|
||||
CHECK_EQ(param.num_nodes, static_cast<int>(stats.size()));
|
||||
fo->Write(¶m, sizeof(TreeParam));
|
||||
CHECK_NE(param.num_nodes, 0);
|
||||
fo->Write(BeginPtr(nodes), sizeof(Node) * nodes.size());
|
||||
fo->Write(BeginPtr(stats), sizeof(NodeStat) * nodes.size());
|
||||
fo->Write(dmlc::BeginPtr(nodes), sizeof(Node) * nodes.size());
|
||||
fo->Write(dmlc::BeginPtr(stats), sizeof(NodeStat) * nodes.size());
|
||||
if (param.size_leaf_vector != 0) fo->Write(leaf_vector);
|
||||
}
|
||||
/*!
|
||||
|
||||
83
include/xgboost/tree_updater.h
Normal file
83
include/xgboost/tree_updater.h
Normal file
@@ -0,0 +1,83 @@
|
||||
/*!
|
||||
* Copyright 2014 by Contributors
|
||||
* \file tree_updater.h
|
||||
* \brief General primitive for tree learning,
|
||||
* Updating a collection of trees given the information.
|
||||
* \author Tianqi Chen
|
||||
*/
|
||||
#ifndef XGBOOST_TREE_UPDATER_H_
|
||||
#define XGBOOST_TREE_UPDATER_H_
|
||||
|
||||
#include <dmlc/registry.h>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
#include "./base.h"
|
||||
#include "./data.h"
|
||||
#include "./tree_model.h"
|
||||
|
||||
namespace xgboost {
|
||||
/*!
|
||||
* \brief interface of tree update module, that performs update of a tree.
|
||||
*/
|
||||
class TreeUpdater {
|
||||
public:
|
||||
/*! \brief virtual destructor */
|
||||
virtual ~TreeUpdater() {}
|
||||
/*!
|
||||
* \brief Initialize the updater with given arguments.
|
||||
* \param args arguments to the objective function.
|
||||
*/
|
||||
virtual void Init(const std::vector<std::pair<std::string, std::string> >& args) = 0;
|
||||
/*!
|
||||
* \brief perform update to the tree models
|
||||
* \param gpair the gradient pair statistics of the data
|
||||
* \param dmat The data matrix passed to the updater.
|
||||
* \param trees references the trees to be updated, updater will change the content of trees
|
||||
* note: all the trees in the vector are updated, with the same statistics,
|
||||
* but maybe different random seeds, usually one tree is passed in at a time,
|
||||
* there can be multiple trees when we train random forest style model
|
||||
*/
|
||||
virtual void Update(const std::vector<bst_gpair>& gpair,
|
||||
DMatrix* data,
|
||||
const std::vector<RegTree*>& trees) = 0;
|
||||
/*!
|
||||
* \brief this is simply a function for optimizing performance
|
||||
* this function asks the updater to return the leaf position of each instance in the previous performed update.
|
||||
* if it is cached in the updater, if it is not available, return nullptr
|
||||
* \return array of leaf position of each instance in the last updated tree
|
||||
*/
|
||||
virtual const int* GetLeafPosition() const {
|
||||
return nullptr;
|
||||
}
|
||||
/*!
|
||||
* \brief Create a tree updater given name
|
||||
* \param name Name of the tree updater.
|
||||
*/
|
||||
static TreeUpdater* Create(const char* name);
|
||||
};
|
||||
|
||||
/*!
|
||||
* \brief Registry entry for tree updater.
|
||||
*/
|
||||
struct TreeUpdaterReg
|
||||
: public dmlc::FunctionRegEntryBase<TreeUpdaterReg,
|
||||
std::function<TreeUpdater* ()> > {
|
||||
};
|
||||
|
||||
/*!
|
||||
* \brief Macro to register tree updater.
|
||||
*
|
||||
* \code
|
||||
* // example of registering a objective ndcg@k
|
||||
* XGBOOST_REGISTER_METRIC(ColMaker, "colmaker")
|
||||
* .describe("Column based tree maker.")
|
||||
* .set_body([]() {
|
||||
* return new ColMaker<TStats>();
|
||||
* });
|
||||
* \endcode
|
||||
*/
|
||||
#define XGBOOST_REGISTER_TREE_UPDATER(UniqueId, Name) \
|
||||
static ::xgboost::TreeUpdaterReg & __make_ ## TreeUpdaterReg ## _ ## UniqueId ## __ = \
|
||||
::dmlc::Registry< ::xgboost::TreeUpdaterReg>::Get()->__REGISTER__(#Name)
|
||||
} // namespace xgboost
|
||||
#endif // XGBOOST_TREE_UPDATER_H_
|
||||
Reference in New Issue
Block a user