Commit 8425fbea authored by Tony-Y's avatar Tony-Y Committed by Qiwei Ye
Browse files

Fix coding style (#969) (#970)

Function names must be in the "Pascal Case" style.

* check_elements_interval_closed to CheckElementsIntervalClosed

* obtain_min_max_sum to ObtainMinMaxSum
parent d3e88ef5
...@@ -580,7 +580,7 @@ static void ParallelSort(_RanIt _First, _RanIt _Last, _Pr _Pred) { ...@@ -580,7 +580,7 @@ static void ParallelSort(_RanIt _First, _RanIt _Last, _Pr _Pred) {
} }
// Check that all y[] are in interval [ymin, ymax] (end points included); throws error if not // Check that all y[] are in interval [ymin, ymax] (end points included); throws error if not
inline void check_elements_interval_closed(const float *y, float ymin, float ymax, int ny, const char *callername) { inline void CheckElementsIntervalClosed(const float *y, float ymin, float ymax, int ny, const char *callername) {
for (int i = 0; i < ny; ++i) { for (int i = 0; i < ny; ++i) {
if (y[i] < ymin || y[i] > ymax) { if (y[i] < ymin || y[i] > ymax) {
Log::Fatal("[%s]: does not tolerate element [#%i = %f] outside [%f, %f]", callername, i, y[i], ymin, ymax); Log::Fatal("[%s]: does not tolerate element [#%i = %f] outside [%f, %f]", callername, i, y[i], ymin, ymax);
...@@ -590,7 +590,7 @@ inline void check_elements_interval_closed(const float *y, float ymin, float yma ...@@ -590,7 +590,7 @@ inline void check_elements_interval_closed(const float *y, float ymin, float yma
// One-pass scan over array w with nw elements: find min, max and sum of elements; // One-pass scan over array w with nw elements: find min, max and sum of elements;
// this is useful for checking weight requirements. // this is useful for checking weight requirements.
inline void obtain_min_max_sum(const float *w, int nw, float *mi, float *ma, double *su) { inline void ObtainMinMaxSum(const float *w, int nw, float *mi, float *ma, double *su) {
float minw = w[0]; float minw = w[0];
float maxw = w[0]; float maxw = w[0];
double sumw = static_cast<double>(w[0]); double sumw = static_cast<double>(w[0]);
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include <vector> #include <vector>
#include <sstream> #include <sstream>
/* /*
* Implements three related metrics: * Implements three related metrics:
* *
* (1) standard cross-entropy that can be used for continuous labels in [0, 1] * (1) standard cross-entropy that can be used for continuous labels in [0, 1]
...@@ -79,7 +79,7 @@ public: ...@@ -79,7 +79,7 @@ public:
CHECK_NOTNULL(label_); CHECK_NOTNULL(label_);
// ensure that labels are in interval [0, 1], interval ends included // ensure that labels are in interval [0, 1], interval ends included
Common::check_elements_interval_closed(label_, 0.0f, 1.0f, num_data_, GetName()[0].c_str()); Common::CheckElementsIntervalClosed(label_, 0.0f, 1.0f, num_data_, GetName()[0].c_str());
Log::Info("[%s:%s]: (metric) labels passed interval [0, 1] check", GetName()[0].c_str(), __func__); Log::Info("[%s:%s]: (metric) labels passed interval [0, 1] check", GetName()[0].c_str(), __func__);
// check that weights are non-negative and sum is positive // check that weights are non-negative and sum is positive
...@@ -87,7 +87,7 @@ public: ...@@ -87,7 +87,7 @@ public:
sum_weights_ = static_cast<double>(num_data_); sum_weights_ = static_cast<double>(num_data_);
} else { } else {
float minw; float minw;
Common::obtain_min_max_sum(weights_, num_data_, &minw, nullptr, &sum_weights_); Common::ObtainMinMaxSum(weights_, num_data_, &minw, nullptr, &sum_weights_);
if (minw < 0.0f) { if (minw < 0.0f) {
Log::Fatal("[%s:%s]: (metric) weights not allowed to be negative", GetName()[0].c_str(), __func__); Log::Fatal("[%s:%s]: (metric) weights not allowed to be negative", GetName()[0].c_str(), __func__);
} }
...@@ -172,18 +172,18 @@ public: ...@@ -172,18 +172,18 @@ public:
weights_ = metadata.weights(); weights_ = metadata.weights();
CHECK_NOTNULL(label_); CHECK_NOTNULL(label_);
Common::check_elements_interval_closed(label_, 0.0f, 1.0f, num_data_, GetName()[0].c_str()); Common::CheckElementsIntervalClosed(label_, 0.0f, 1.0f, num_data_, GetName()[0].c_str());
Log::Info("[%s:%s]: (metric) labels passed interval [0, 1] check", GetName()[0].c_str(), __func__); Log::Info("[%s:%s]: (metric) labels passed interval [0, 1] check", GetName()[0].c_str(), __func__);
// check all weights are strictly positive; throw error if not // check all weights are strictly positive; throw error if not
if (weights_ != nullptr) { if (weights_ != nullptr) {
float minw; float minw;
Common::obtain_min_max_sum(weights_, num_data_, &minw, nullptr, nullptr); Common::ObtainMinMaxSum(weights_, num_data_, &minw, nullptr, nullptr);
if (minw <= 0.0f) { if (minw <= 0.0f) {
Log::Fatal("[%s:%s]: (metric) all weights must be positive", GetName()[0].c_str(), __func__); Log::Fatal("[%s:%s]: (metric) all weights must be positive", GetName()[0].c_str(), __func__);
} }
} }
} }
std::vector<double> Eval(const double* score, const ObjectiveFunction* objective) const override { std::vector<double> Eval(const double* score, const ObjectiveFunction* objective) const override {
...@@ -256,14 +256,14 @@ public: ...@@ -256,14 +256,14 @@ public:
weights_ = metadata.weights(); weights_ = metadata.weights();
CHECK_NOTNULL(label_); CHECK_NOTNULL(label_);
Common::check_elements_interval_closed(label_, 0.0f, 1.0f, num_data_, GetName()[0].c_str()); Common::CheckElementsIntervalClosed(label_, 0.0f, 1.0f, num_data_, GetName()[0].c_str());
Log::Info("[%s:%s]: (metric) labels passed interval [0, 1] check", GetName()[0].c_str(), __func__); Log::Info("[%s:%s]: (metric) labels passed interval [0, 1] check", GetName()[0].c_str(), __func__);
if (weights_ == nullptr) { if (weights_ == nullptr) {
sum_weights_ = static_cast<double>(num_data_); sum_weights_ = static_cast<double>(num_data_);
} else { } else {
float minw; float minw;
Common::obtain_min_max_sum(weights_, num_data_, &minw, nullptr, &sum_weights_); Common::ObtainMinMaxSum(weights_, num_data_, &minw, nullptr, &sum_weights_);
if (minw < 0.0f) { if (minw < 0.0f) {
Log::Fatal("[%s:%s]: (metric) at least one weight is negative", GetName()[0].c_str(), __func__); Log::Fatal("[%s:%s]: (metric) at least one weight is negative", GetName()[0].c_str(), __func__);
} }
......
...@@ -318,7 +318,7 @@ public: ...@@ -318,7 +318,7 @@ public:
// Safety check of labels // Safety check of labels
float miny; float miny;
double sumy; double sumy;
Common::obtain_min_max_sum(label_, num_data_, &miny, nullptr, &sumy); Common::ObtainMinMaxSum(label_, num_data_, &miny, nullptr, &sumy);
if (miny < 0.0f) { if (miny < 0.0f) {
Log::Fatal("[%s]: at least one target label is negative.", GetName()); Log::Fatal("[%s]: at least one target label is negative.", GetName());
} }
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* Target y is anything in interval [0, 1]. * Target y is anything in interval [0, 1].
* *
* (1) CrossEntropy; "xentropy"; * (1) CrossEntropy; "xentropy";
* *
* loss(y, p, w) = { -(1-y)*log(1-p)-y*log(p) }*w, * loss(y, p, w) = { -(1-y)*log(1-p)-y*log(p) }*w,
* with probability p = 1/(1+exp(-f)), where f is being boosted * with probability p = 1/(1+exp(-f)), where f is being boosted
* *
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
* *
* (2) CrossEntropyLambda; "xentlambda" * (2) CrossEntropyLambda; "xentlambda"
* *
* loss(y, p, w) = -(1-y)*log(1-p)-y*log(p), * loss(y, p, w) = -(1-y)*log(1-p)-y*log(p),
* with p = 1-exp(-lambda*w), lambda = log(1+exp(f)), f being boosted, and w > 0 * with p = 1-exp(-lambda*w), lambda = log(1+exp(f)), f being boosted, and w > 0
* *
* ConvertToOutput: f -> lambda * ConvertToOutput: f -> lambda
...@@ -52,13 +52,13 @@ public: ...@@ -52,13 +52,13 @@ public:
weights_ = metadata.weights(); weights_ = metadata.weights();
CHECK_NOTNULL(label_); CHECK_NOTNULL(label_);
Common::check_elements_interval_closed(label_, 0.0f, 1.0f, num_data_, GetName()); Common::CheckElementsIntervalClosed(label_, 0.0f, 1.0f, num_data_, GetName());
Log::Info("[%s:%s]: (objective) labels passed interval [0, 1] check", GetName(), __func__); Log::Info("[%s:%s]: (objective) labels passed interval [0, 1] check", GetName(), __func__);
if (weights_ != nullptr) { if (weights_ != nullptr) {
float minw; float minw;
double sumw; double sumw;
Common::obtain_min_max_sum(weights_, num_data_, &minw, nullptr, &sumw); Common::ObtainMinMaxSum(weights_, num_data_, &minw, nullptr, &sumw);
if (minw < 0.0f) { if (minw < 0.0f) {
Log::Fatal("[%s]: at least one weight is negative.", GetName()); Log::Fatal("[%s]: at least one weight is negative.", GetName());
} }
...@@ -66,7 +66,7 @@ public: ...@@ -66,7 +66,7 @@ public:
Log::Fatal("[%s]: sum of weights is zero.", GetName()); Log::Fatal("[%s]: sum of weights is zero.", GetName());
} }
} }
} }
void GetGradients(const double* score, score_t* gradients, score_t* hessians) const override { void GetGradients(const double* score, score_t* gradients, score_t* hessians) const override {
...@@ -158,24 +158,24 @@ public: ...@@ -158,24 +158,24 @@ public:
weights_ = metadata.weights(); weights_ = metadata.weights();
CHECK_NOTNULL(label_); CHECK_NOTNULL(label_);
Common::check_elements_interval_closed(label_, 0.0f, 1.0f, num_data_, GetName()); Common::CheckElementsIntervalClosed(label_, 0.0f, 1.0f, num_data_, GetName());
Log::Info("[%s:%s]: (objective) labels passed interval [0, 1] check", GetName(), __func__); Log::Info("[%s:%s]: (objective) labels passed interval [0, 1] check", GetName(), __func__);
if (weights_ != nullptr) { if (weights_ != nullptr) {
Common::obtain_min_max_sum(weights_, num_data_, &min_weight_, &max_weight_, nullptr); Common::ObtainMinMaxSum(weights_, num_data_, &min_weight_, &max_weight_, nullptr);
if (min_weight_ <= 0.0f) { if (min_weight_ <= 0.0f) {
Log::Fatal("[%s]: at least one weight is non-positive.", GetName()); Log::Fatal("[%s]: at least one weight is non-positive.", GetName());
} }
// Issue an info statement about this ratio // Issue an info statement about this ratio
double weight_ratio = max_weight_ / min_weight_; double weight_ratio = max_weight_ / min_weight_;
Log::Info("[%s:%s]: min, max weights = %f, %f; ratio = %f", Log::Info("[%s:%s]: min, max weights = %f, %f; ratio = %f",
GetName(), __func__, GetName(), __func__,
min_weight_, max_weight_, min_weight_, max_weight_,
weight_ratio); weight_ratio);
} else { } else {
// all weights are implied to be unity; no need to do anything // all weights are implied to be unity; no need to do anything
} }
} }
......
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