Skip to content

Commit

Permalink
fix test compilation issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Nan Zhu committed Feb 5, 2019
1 parent f218bc0 commit 9ec04cd
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 102 deletions.
1 change: 0 additions & 1 deletion src/tree/updater_quantile_hist.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ void QuantileHistMaker::Builder::ExpandWithDepthWidth(
DMatrix *p_fmat,
RegTree *p_tree,
const std::vector<GradientPair> &gpair_h) {

unsigned timestamp = 0;
int num_leaves = 0;
// FIXME(hcho3): this code is broken when param.num_roots > 1. Please fix it
Expand Down
198 changes: 99 additions & 99 deletions src/tree/updater_quantile_hist.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,33 +119,33 @@ class QuantileHistMaker: public TreeUpdater {
HostDeviceVector<bst_float>* p_out_preds);

protected:
// initialize temp data structure
void InitData(const GHistIndexMatrix& gmat,
// initialize temp data structure
void InitData(const GHistIndexMatrix& gmat,
const std::vector<GradientPair>& gpair,
const DMatrix& fmat,
const RegTree& tree);

void EvaluateSplit(int nid,
void EvaluateSplit(int nid,
const GHistIndexMatrix& gmat,
const HistCollection& hist,
const DMatrix& fmat,
const RegTree& tree);

void ApplySplit(int nid,
void ApplySplit(int nid,
const GHistIndexMatrix& gmat,
const ColumnMatrix& column_matrix,
const HistCollection& hist,
const DMatrix& fmat,
RegTree* p_tree);

void ApplySplitDenseData(const RowSetCollection::Elem rowset,
void ApplySplitDenseData(const RowSetCollection::Elem rowset,
const GHistIndexMatrix& gmat,
std::vector<RowSetCollection::Split>* p_row_split_tloc,
const Column& column,
bst_int split_cond,
bool default_left);

void ApplySplitSparseData(const RowSetCollection::Elem rowset,
void ApplySplitSparseData(const RowSetCollection::Elem rowset,
const GHistIndexMatrix& gmat,
std::vector<RowSetCollection::Split>* p_row_split_tloc,
const Column& column,
Expand All @@ -154,14 +154,14 @@ class QuantileHistMaker: public TreeUpdater {
bst_int split_cond,
bool default_left);

void InitNewNode(int nid,
void InitNewNode(int nid,
const GHistIndexMatrix& gmat,
const std::vector<GradientPair>& gpair,
const DMatrix& fmat,
const RegTree& tree);

// enumerate the split values of specific feature
void EnumerateSplit(int d_step,
// enumerate the split values of specific feature
void EnumerateSplit(int d_step,
const GHistIndexMatrix& gmat,
const GHistRow& hist,
const NodeEntry& snode,
Expand All @@ -170,109 +170,109 @@ class QuantileHistMaker: public TreeUpdater {
bst_uint fid,
bst_uint nodeID);

void ExpandWithDepthWidth(const GHistIndexMatrix &gmat,
void ExpandWithDepthWidth(const GHistIndexMatrix &gmat,
const GHistIndexBlockMatrix &gmatb,
const ColumnMatrix &column_matrix,
DMatrix *p_fmat,
RegTree *p_tree,
const std::vector<GradientPair> &gpair_h);

void ExpandWithLossGuide(const GHistIndexMatrix& gmat,
void ExpandWithLossGuide(const GHistIndexMatrix& gmat,
const GHistIndexBlockMatrix& gmatb,
const ColumnMatrix& column_matrix,
DMatrix* p_fmat,
RegTree* p_tree,
const std::vector<GradientPair>& gpair_h);

/* tree growing policies */
struct ExpandEntry {
int nid;
int depth;
bst_float loss_chg;
unsigned timestamp;
ExpandEntry(int nid, int depth, bst_float loss_chg, unsigned tstmp)
: nid(nid), depth(depth), loss_chg(loss_chg), timestamp(tstmp) {}
};
inline static bool DepthWise(ExpandEntry lhs, ExpandEntry rhs) {
if (lhs.depth == rhs.depth) {
return lhs.timestamp > rhs.timestamp; // favor small timestamp
} else {
return lhs.depth > rhs.depth; // favor small depth
}
}
inline static bool LossGuide(ExpandEntry lhs, ExpandEntry rhs) {
if (lhs.loss_chg == rhs.loss_chg) {
return lhs.timestamp > rhs.timestamp; // favor small timestamp
} else {
return lhs.loss_chg < rhs.loss_chg; // favor large loss_chg
}
}

// --data fields--
const TrainParam& param_;
// number of omp thread used during training
int nthread_;
common::ColumnSampler column_sampler_;
// the internal row sets
RowSetCollection row_set_collection_;
// the temp space for split
std::vector<RowSetCollection::Split> row_split_tloc_;
std::vector<SplitEntry> best_split_tloc_;
/*! \brief TreeNode Data: statistics for each constructed node */
std::vector<NodeEntry> snode_;
/*! \brief culmulative histogram of gradients. */
HistCollection hist_;
/*! \brief feature with least # of bins. to be used for dense specialization
of InitNewNode() */
uint32_t fid_least_bins_;
/*! \brief local prediction cache; maps node id to leaf value */
std::vector<float> leaf_value_cache_;

GHistBuilder hist_builder_;
std::unique_ptr<TreeUpdater> pruner_;
std::unique_ptr<SplitEvaluator> spliteval_;

// back pointers to tree and data matrix
const RegTree* p_last_tree_;
const DMatrix* p_last_fmat_;

using ExpandQueue =
std::priority_queue<ExpandEntry, std::vector<ExpandEntry>,
std::function<bool(ExpandEntry, ExpandEntry)>>;

std::unique_ptr<ExpandQueue> qexpand_loss_guided;
std::vector<ExpandEntry> qexpand_depth_wise;
// key is the node id which should be calculated by SubstractTrick, value is the node is which
// provides the evidence for substracts
std::unordered_map<int, int> nodes_to_derive;
std::unordered_map<int, int> left_to_right_siblings;
std::unordered_map<int, int> right_to_left_siblings;

inline bool IsLeft(int nid) {
return left_to_right_siblings.find(nid) != left_to_right_siblings.end();
}

inline bool IsRight(int nid) {
return right_to_left_siblings.find(nid) != right_to_left_siblings.end();
}

inline bool IsRoot(int nid) {
return (right_to_left_siblings.find(nid) == right_to_left_siblings.end() &&
left_to_right_siblings.find(nid) == left_to_right_siblings.end());
}

enum DataLayout { kDenseDataZeroBased, kDenseDataOneBased, kSparseData };
DataLayout data_layout_;

// performance counters
double tstart;
double time_init_data = 0;
double time_init_new_node = 0;
double time_build_hist = 0;
double time_evaluate_split = 0;
double time_apply_split = 0;

rabit::Reducer<GHistEntry, GHistEntry::Reduce> histred_;
struct ExpandEntry {
int nid;
int depth;
bst_float loss_chg;
unsigned timestamp;
ExpandEntry(int nid, int depth, bst_float loss_chg, unsigned tstmp)
: nid(nid), depth(depth), loss_chg(loss_chg), timestamp(tstmp) {}
};
inline static bool DepthWise(ExpandEntry lhs, ExpandEntry rhs) {
if (lhs.depth == rhs.depth) {
return lhs.timestamp > rhs.timestamp; // favor small timestamp
} else {
return lhs.depth > rhs.depth; // favor small depth
}
}
inline static bool LossGuide(ExpandEntry lhs, ExpandEntry rhs) {
if (lhs.loss_chg == rhs.loss_chg) {
return lhs.timestamp > rhs.timestamp; // favor small timestamp
} else {
return lhs.loss_chg < rhs.loss_chg; // favor large loss_chg
}
}

// --data fields--
const TrainParam& param_;
// number of omp thread used during training
int nthread_;
common::ColumnSampler column_sampler_;
// the internal row sets
RowSetCollection row_set_collection_;
// the temp space for split
std::vector<RowSetCollection::Split> row_split_tloc_;
std::vector<SplitEntry> best_split_tloc_;
/*! \brief TreeNode Data: statistics for each constructed node */
std::vector<NodeEntry> snode_;
/*! \brief culmulative histogram of gradients. */
HistCollection hist_;
/*! \brief feature with least # of bins. to be used for dense specialization
of InitNewNode() */
uint32_t fid_least_bins_;
/*! \brief local prediction cache; maps node id to leaf value */
std::vector<float> leaf_value_cache_;

GHistBuilder hist_builder_;
std::unique_ptr<TreeUpdater> pruner_;
std::unique_ptr<SplitEvaluator> spliteval_;

// back pointers to tree and data matrix
const RegTree* p_last_tree_;
const DMatrix* p_last_fmat_;

using ExpandQueue =
std::priority_queue<ExpandEntry, std::vector<ExpandEntry>,
std::function<bool(ExpandEntry, ExpandEntry)>>;

std::unique_ptr<ExpandQueue> qexpand_loss_guided;
std::vector<ExpandEntry> qexpand_depth_wise;
// key is the node id which should be calculated by SubstractTrick, value is the node is which
// provides the evidence for substracts
std::unordered_map<int, int> nodes_to_derive;
std::unordered_map<int, int> left_to_right_siblings;
std::unordered_map<int, int> right_to_left_siblings;

inline bool IsLeft(int nid) {
return left_to_right_siblings.find(nid) != left_to_right_siblings.end();
}

inline bool IsRight(int nid) {
return right_to_left_siblings.find(nid) != right_to_left_siblings.end();
}

inline bool IsRoot(int nid) {
return (right_to_left_siblings.find(nid) == right_to_left_siblings.end() &&
left_to_right_siblings.find(nid) == left_to_right_siblings.end());
}

enum DataLayout { kDenseDataZeroBased, kDenseDataOneBased, kSparseData };
DataLayout data_layout_;

// performance counters
double tstart;
double time_init_data = 0;
double time_init_new_node = 0;
double time_build_hist = 0;
double time_evaluate_split = 0;
double time_apply_split = 0;

rabit::Reducer<GHistEntry, GHistEntry::Reduce> histred_;
};

std::unique_ptr<Builder> builder_;
Expand Down
4 changes: 2 additions & 2 deletions tests/cpp/tree/test_quantile_hist.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class QuantileHistMock : public QuantileHistMaker {
GHistIndexBlockMatrix quantile_index_block;
hist_.AddHistRow(nid);
BuildHist(gpair, row_set_collection_[nid],
gmat, quantile_index_block, hist_[nid]);
gmat, quantile_index_block, hist_[nid], false);
std::vector<GradientPairPrecise> solution {
{0.27f, 0.29f}, {0.27f, 0.29f}, {0.47f, 0.49f},
{0.27f, 0.29f}, {0.57f, 0.59f}, {0.26f, 0.27f},
Expand Down Expand Up @@ -79,7 +79,7 @@ class QuantileHistMock : public QuantileHistMaker {
hist_.AddHistRow(0);

BuildHist(row_gpairs, row_set_collection_[0],
gmat, quantile_index_block, hist_[0]);
gmat, quantile_index_block, hist_[0], false);

RealImpl::InitNewNode(0, gmat, row_gpairs, *(*dmat), tree);
// Manipulate the root_gain so that I don't have to invent an actual
Expand Down

0 comments on commit 9ec04cd

Please sign in to comment.