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) {
}
// 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) {
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);
......@@ -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;
// 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 maxw = w[0];
double sumw = static_cast<double>(w[0]);
......
......@@ -12,7 +12,7 @@
#include <vector>
#include <sstream>
/*
/*
* Implements three related metrics:
*
* (1) standard cross-entropy that can be used for continuous labels in [0, 1]
......@@ -79,7 +79,7 @@ public:
CHECK_NOTNULL(label_);
// 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__);
// check that weights are non-negative and sum is positive
......@@ -87,7 +87,7 @@ public:
sum_weights_ = static_cast<double>(num_data_);
} else {
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) {
Log::Fatal("[%s:%s]: (metric) weights not allowed to be negative", GetName()[0].c_str(), __func__);
}
......@@ -172,18 +172,18 @@ public:
weights_ = metadata.weights();
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__);
// check all weights are strictly positive; throw error if not
if (weights_ != nullptr) {
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) {
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 {
......@@ -256,14 +256,14 @@ public:
weights_ = metadata.weights();
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__);
if (weights_ == nullptr) {
sum_weights_ = static_cast<double>(num_data_);
} else {
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) {
Log::Fatal("[%s:%s]: (metric) at least one weight is negative", GetName()[0].c_str(), __func__);
}
......
......@@ -318,7 +318,7 @@ public:
// Safety check of labels
float miny;
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) {
Log::Fatal("[%s]: at least one target label is negative.", GetName());
}
......
......@@ -15,7 +15,7 @@
* Target y is anything in interval [0, 1].
*
* (1) CrossEntropy; "xentropy";
*
*
* 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
*
......@@ -23,7 +23,7 @@
*
* (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
*
* ConvertToOutput: f -> lambda
......@@ -52,13 +52,13 @@ public:
weights_ = metadata.weights();
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__);
if (weights_ != nullptr) {
float minw;
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) {
Log::Fatal("[%s]: at least one weight is negative.", GetName());
}
......@@ -66,7 +66,7 @@ public:
Log::Fatal("[%s]: sum of weights is zero.", GetName());
}
}
}
void GetGradients(const double* score, score_t* gradients, score_t* hessians) const override {
......@@ -158,24 +158,24 @@ public:
weights_ = metadata.weights();
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__);
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) {
Log::Fatal("[%s]: at least one weight is non-positive.", GetName());
}
// Issue an info statement about this ratio
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__,
min_weight_, max_weight_,
weight_ratio);
} 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