Unverified Commit 532722b9 authored by Nikita Titov's avatar Nikita Titov Committed by GitHub
Browse files

fixed cpplint errors and VS project files (#2873)

parent 67d56b26
...@@ -7,12 +7,11 @@ ...@@ -7,12 +7,11 @@
#include <LightGBM/config.h> #include <LightGBM/config.h>
#include <LightGBM/meta.h> #include <LightGBM/meta.h>
#include <LightGBM/utils/json11.h>
#include <string> #include <string>
#include <vector> #include <vector>
#include <LightGBM/utils/json11.h>
namespace LightGBM { namespace LightGBM {
using json11::Json; using json11::Json;
...@@ -54,7 +53,6 @@ class TreeLearner { ...@@ -54,7 +53,6 @@ class TreeLearner {
* \brief training tree model on dataset * \brief training tree model on dataset
* \param gradients The first order gradients * \param gradients The first order gradients
* \param hessians The second order gradients * \param hessians The second order gradients
* \param is_constant_hessian True if all hessians share the same value
* \return A trained tree * \return A trained tree
*/ */
virtual Tree* Train(const score_t* gradients, const score_t* hessians) = 0; virtual Tree* Train(const score_t* gradients, const score_t* hessians) = 0;
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <LightGBM/boosting.h> #include <LightGBM/boosting.h>
#include <LightGBM/objective_function.h> #include <LightGBM/objective_function.h>
#include <LightGBM/prediction_early_stop.h> #include <LightGBM/prediction_early_stop.h>
#include <LightGBM/utils/json11.h>
#include <LightGBM/utils/threading.h> #include <LightGBM/utils/threading.h>
#include <string> #include <string>
...@@ -21,7 +22,6 @@ ...@@ -21,7 +22,6 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include <LightGBM/utils/json11.h>
#include "score_updater.hpp" #include "score_updater.hpp"
namespace LightGBM { namespace LightGBM {
......
...@@ -6,13 +6,12 @@ ...@@ -6,13 +6,12 @@
#include <LightGBM/network.h> #include <LightGBM/network.h>
#include <LightGBM/utils/array_args.h> #include <LightGBM/utils/array_args.h>
#include <LightGBM/utils/json11.h>
#include <LightGBM/utils/log.h> #include <LightGBM/utils/log.h>
#include <LightGBM/utils/openmp_wrapper.h> #include <LightGBM/utils/openmp_wrapper.h>
#include <fstream> #include <fstream>
#include <LightGBM/utils/json11.h>
namespace LightGBM { namespace LightGBM {
using json11::Json; using json11::Json;
......
...@@ -8,15 +8,17 @@ ...@@ -8,15 +8,17 @@
#include <LightGBM/dataset.h> #include <LightGBM/dataset.h>
#include <LightGBM/meta.h> #include <LightGBM/meta.h>
#include <LightGBM/utils/common.h> #include <LightGBM/utils/common.h>
#include <LightGBM/utils/openmp_wrapper.h> #include <LightGBM/utils/openmp_wrapper.h>
#include <LightGBM/utils/random.h> #include <LightGBM/utils/random.h>
#include <algorithm>
#include <vector>
namespace LightGBM { namespace LightGBM {
class ColSampler { class ColSampler {
public: public:
ColSampler(const Config* config) explicit ColSampler(const Config* config)
: fraction_bytree_(config->feature_fraction), : fraction_bytree_(config->feature_fraction),
fraction_bynode_(config->feature_fraction_bynode), fraction_bynode_(config->feature_fraction_bynode),
seed_(config->feature_fraction_seed), seed_(config->feature_fraction_seed),
......
...@@ -35,7 +35,6 @@ class FeatureMetainfo { ...@@ -35,7 +35,6 @@ class FeatureMetainfo {
BinType bin_type; BinType bin_type;
/*! \brief random number generator for extremely randomized trees */ /*! \brief random number generator for extremely randomized trees */
mutable Random rand; mutable Random rand;
;
}; };
/*! /*!
* \brief FeatureHistogram is used to construct and store a histogram for a * \brief FeatureHistogram is used to construct and store a histogram for a
...@@ -68,6 +67,7 @@ class FeatureHistogram { ...@@ -68,6 +67,7 @@ class FeatureHistogram {
} }
hist_t* RawData() { return data_; } hist_t* RawData() { return data_; }
/*! /*!
* \brief Subtract current histograms with other * \brief Subtract current histograms with other
* \param other The histogram that want to subtract * \param other The histogram that want to subtract
...@@ -300,16 +300,20 @@ class FeatureHistogram { ...@@ -300,16 +300,20 @@ class FeatureHistogram {
static_cast<data_size_t>(Common::RoundInt(hess * cnt_factor)); static_cast<data_size_t>(Common::RoundInt(hess * cnt_factor));
// if data not enough, or sum hessian too small // if data not enough, or sum hessian too small
if (cnt < meta_->config->min_data_in_leaf || if (cnt < meta_->config->min_data_in_leaf ||
hess < meta_->config->min_sum_hessian_in_leaf) hess < meta_->config->min_sum_hessian_in_leaf) {
continue; continue;
}
data_size_t other_count = num_data - cnt; data_size_t other_count = num_data - cnt;
// if data not enough // if data not enough
if (other_count < meta_->config->min_data_in_leaf) continue; if (other_count < meta_->config->min_data_in_leaf) {
continue;
}
double sum_other_hessian = sum_hessian - hess - kEpsilon; double sum_other_hessian = sum_hessian - hess - kEpsilon;
// if sum hessian too small // if sum hessian too small
if (sum_other_hessian < meta_->config->min_sum_hessian_in_leaf) if (sum_other_hessian < meta_->config->min_sum_hessian_in_leaf) {
continue; continue;
}
double sum_other_gradient = sum_gradient - grad; double sum_other_gradient = sum_gradient - grad;
if (USE_RAND) { if (USE_RAND) {
...@@ -323,7 +327,9 @@ class FeatureHistogram { ...@@ -323,7 +327,9 @@ class FeatureHistogram {
meta_->config->lambda_l1, l2, meta_->config->max_delta_step, meta_->config->lambda_l1, l2, meta_->config->max_delta_step,
constraints, 0); constraints, 0);
// gain with split is worse than without split // gain with split is worse than without split
if (current_gain <= min_gain_shift) continue; if (current_gain <= min_gain_shift) {
continue;
}
// mark to is splittable // mark to is splittable
is_splittable_ = true; is_splittable_ = true;
...@@ -392,17 +398,23 @@ class FeatureHistogram { ...@@ -392,17 +398,23 @@ class FeatureHistogram {
cnt_cur_group += cnt; cnt_cur_group += cnt;
if (left_count < meta_->config->min_data_in_leaf || if (left_count < meta_->config->min_data_in_leaf ||
sum_left_hessian < meta_->config->min_sum_hessian_in_leaf) sum_left_hessian < meta_->config->min_sum_hessian_in_leaf) {
continue; continue;
}
data_size_t right_count = num_data - left_count; data_size_t right_count = num_data - left_count;
if (right_count < meta_->config->min_data_in_leaf || if (right_count < meta_->config->min_data_in_leaf ||
right_count < min_data_per_group) right_count < min_data_per_group) {
break; break;
}
double sum_right_hessian = sum_hessian - sum_left_hessian; double sum_right_hessian = sum_hessian - sum_left_hessian;
if (sum_right_hessian < meta_->config->min_sum_hessian_in_leaf) break; if (sum_right_hessian < meta_->config->min_sum_hessian_in_leaf) {
break;
}
if (cnt_cur_group < min_data_per_group) continue; if (cnt_cur_group < min_data_per_group) {
continue;
}
cnt_cur_group = 0; cnt_cur_group = 0;
...@@ -416,7 +428,9 @@ class FeatureHistogram { ...@@ -416,7 +428,9 @@ class FeatureHistogram {
sum_left_gradient, sum_left_hessian, sum_right_gradient, sum_left_gradient, sum_left_hessian, sum_right_gradient,
sum_right_hessian, meta_->config->lambda_l1, l2, sum_right_hessian, meta_->config->lambda_l1, l2,
meta_->config->max_delta_step, constraints, 0); meta_->config->max_delta_step, constraints, 0);
if (current_gain <= min_gain_shift) continue; if (current_gain <= min_gain_shift) {
continue;
}
is_splittable_ = true; is_splittable_ = true;
if (current_gain > best_gain) { if (current_gain > best_gain) {
best_left_count = left_count; best_left_count = left_count;
...@@ -546,7 +560,7 @@ class FeatureHistogram { ...@@ -546,7 +560,7 @@ class FeatureHistogram {
if (std::isnan(current_gain) || current_gain <= min_gain_shift) { if (std::isnan(current_gain) || current_gain <= min_gain_shift) {
output->gain = kMinScore; output->gain = kMinScore;
Log::Warning( Log::Warning(
"'Forced Split' will be ignored since the gain getting worse. "); "'Forced Split' will be ignored since the gain getting worse.");
return; return;
} }
...@@ -806,15 +820,20 @@ class FeatureHistogram { ...@@ -806,15 +820,20 @@ class FeatureHistogram {
right_count += cnt; right_count += cnt;
// if data not enough, or sum hessian too small // if data not enough, or sum hessian too small
if (right_count < meta_->config->min_data_in_leaf || if (right_count < meta_->config->min_data_in_leaf ||
sum_right_hessian < meta_->config->min_sum_hessian_in_leaf) sum_right_hessian < meta_->config->min_sum_hessian_in_leaf) {
continue; continue;
}
data_size_t left_count = num_data - right_count; data_size_t left_count = num_data - right_count;
// if data not enough // if data not enough
if (left_count < meta_->config->min_data_in_leaf) break; if (left_count < meta_->config->min_data_in_leaf) {
break;
}
double sum_left_hessian = sum_hessian - sum_right_hessian; double sum_left_hessian = sum_hessian - sum_right_hessian;
// if sum hessian too small // if sum hessian too small
if (sum_left_hessian < meta_->config->min_sum_hessian_in_leaf) break; if (sum_left_hessian < meta_->config->min_sum_hessian_in_leaf) {
break;
}
double sum_left_gradient = sum_gradient - sum_right_gradient; double sum_left_gradient = sum_gradient - sum_right_gradient;
if (USE_RAND) { if (USE_RAND) {
...@@ -829,7 +848,9 @@ class FeatureHistogram { ...@@ -829,7 +848,9 @@ class FeatureHistogram {
meta_->config->lambda_l2, meta_->config->max_delta_step, meta_->config->lambda_l2, meta_->config->max_delta_step,
constraints, meta_->monotone_type); constraints, meta_->monotone_type);
// gain with split is worse than without split // gain with split is worse than without split
if (current_gain <= min_gain_shift) continue; if (current_gain <= min_gain_shift) {
continue;
}
// mark to is splittable // mark to is splittable
is_splittable_ = true; is_splittable_ = true;
...@@ -883,15 +904,20 @@ class FeatureHistogram { ...@@ -883,15 +904,20 @@ class FeatureHistogram {
} }
// if data not enough, or sum hessian too small // if data not enough, or sum hessian too small
if (left_count < meta_->config->min_data_in_leaf || if (left_count < meta_->config->min_data_in_leaf ||
sum_left_hessian < meta_->config->min_sum_hessian_in_leaf) sum_left_hessian < meta_->config->min_sum_hessian_in_leaf) {
continue; continue;
}
data_size_t right_count = num_data - left_count; data_size_t right_count = num_data - left_count;
// if data not enough // if data not enough
if (right_count < meta_->config->min_data_in_leaf) break; if (right_count < meta_->config->min_data_in_leaf) {
break;
}
double sum_right_hessian = sum_hessian - sum_left_hessian; double sum_right_hessian = sum_hessian - sum_left_hessian;
// if sum hessian too small // if sum hessian too small
if (sum_right_hessian < meta_->config->min_sum_hessian_in_leaf) break; if (sum_right_hessian < meta_->config->min_sum_hessian_in_leaf) {
break;
}
double sum_right_gradient = sum_gradient - sum_left_gradient; double sum_right_gradient = sum_gradient - sum_left_gradient;
if (USE_RAND) { if (USE_RAND) {
...@@ -906,7 +932,9 @@ class FeatureHistogram { ...@@ -906,7 +932,9 @@ class FeatureHistogram {
meta_->config->lambda_l2, meta_->config->max_delta_step, meta_->config->lambda_l2, meta_->config->max_delta_step,
constraints, meta_->monotone_type); constraints, meta_->monotone_type);
// gain with split is worse than without split // gain with split is worse than without split
if (current_gain <= min_gain_shift) continue; if (current_gain <= min_gain_shift) {
continue;
}
// mark to is splittable // mark to is splittable
is_splittable_ = true; is_splittable_ = true;
......
...@@ -177,7 +177,7 @@ Tree* SerialTreeLearner::Train(const score_t* gradients, const score_t *hessians ...@@ -177,7 +177,7 @@ Tree* SerialTreeLearner::Train(const score_t* gradients, const score_t *hessians
if (BeforeFindBestSplit(tree_prt, left_leaf, right_leaf)) { if (BeforeFindBestSplit(tree_prt, left_leaf, right_leaf)) {
// find best threshold for every feature // find best threshold for every feature
FindBestSplits(); FindBestSplits();
} }
// Get a leaf with max split gain // Get a leaf with max split gain
int best_leaf = static_cast<int>(ArrayArgs<SplitInfo>::ArgMax(best_split_per_leaf_)); int best_leaf = static_cast<int>(ArrayArgs<SplitInfo>::ArgMax(best_split_per_leaf_));
// Get split information for best leaf // Get split information for best leaf
...@@ -515,7 +515,7 @@ int32_t SerialTreeLearner::ForceSplits(Tree* tree, int* left_leaf, ...@@ -515,7 +515,7 @@ int32_t SerialTreeLearner::ForceSplits(Tree* tree, int* left_leaf,
} }
Split(tree, best_leaf, left_leaf, right_leaf); Split(tree, best_leaf, left_leaf, right_leaf);
*(cur_depth) = std::max(*(cur_depth), tree->leaf_depth(*left_leaf)); *(cur_depth) = std::max(*(cur_depth), tree->leaf_depth(*left_leaf));
result_count++; ++result_count;
} }
return result_count; return result_count;
} }
......
...@@ -281,6 +281,7 @@ ...@@ -281,6 +281,7 @@
<ClInclude Include="..\src\objective\regression_objective.hpp" /> <ClInclude Include="..\src\objective\regression_objective.hpp" />
<ClInclude Include="..\src\objective\multiclass_objective.hpp" /> <ClInclude Include="..\src\objective\multiclass_objective.hpp" />
<ClInclude Include="..\src\objective\xentropy_objective.hpp" /> <ClInclude Include="..\src\objective\xentropy_objective.hpp" />
<ClInclude Include="..\src\treelearner\col_sampler.hpp" />
<ClInclude Include="..\src\treelearner\cost_effective_gradient_boosting.hpp" /> <ClInclude Include="..\src\treelearner\cost_effective_gradient_boosting.hpp" />
<ClInclude Include="..\src\treelearner\data_partition.hpp" /> <ClInclude Include="..\src\treelearner\data_partition.hpp" />
<ClInclude Include="..\src\treelearner\feature_histogram.hpp" /> <ClInclude Include="..\src\treelearner\feature_histogram.hpp" />
......
...@@ -213,6 +213,9 @@ ...@@ -213,6 +213,9 @@
<ClInclude Include="..\include\LightGBM\utils\json11.h"> <ClInclude Include="..\include\LightGBM\utils\json11.h">
<Filter>include\LightGBM\utils</Filter> <Filter>include\LightGBM\utils</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\src\treelearner\col_sampler.hpp">
<Filter>src\treelearner</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\src\application\application.cpp"> <ClCompile Include="..\src\application\application.cpp">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment