-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added method for customizable "boost-from-average" (#731)
* Created objectives and metrics xentropy and xentropy1 * Some coment and code cleanup. * Added Kullback-Leibler version of metric. Changed some warning messages. * Fixed sign error in KL-divergence calc. * Removed __PRETTY_FUNCTION__. * Fixed better name for alternative xentropy parameterization. Documented details on the objectives / metrics in code comments. * Common code for label interval checks. Cleanups. * Use common utility for various weight property checks. * Added code for customizable initial average to boost from. * Fixed spelling error in aliases.
- Loading branch information
Showing
4 changed files
with
49 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,8 +102,31 @@ class CrossEntropy: public ObjectiveFunction { | |
return str_buf.str(); | ||
} | ||
|
||
// allow boost from average option | ||
bool BoostFromAverage() const override { return true; } | ||
|
||
// implement custom average to boost from (if enabled among options) | ||
bool GetCustomAverage(double *initscore) const override { | ||
if (initscore == nullptr) return false; | ||
double suml = 0.0f; | ||
double sumw = 0.0f; | ||
if (weights_ == nullptr) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
for (data_size_t i = 0; i < num_data_; ++i) { | ||
suml += label_[i] * weights_[i]; | ||
sumw += weights_[i]; | ||
} | ||
} else { | ||
sumw = static_cast<double>(num_data_); | ||
for (data_size_t i = 0; i < num_data_; ++i) { | ||
suml += label_[i]; | ||
} | ||
} | ||
double pavg = suml / sumw; | ||
*initscore = std::log(pavg / (1.0f - pavg)); | ||
Log::Info("[%s:%s]: pavg=%f -> initscore=%f", GetName(), __func__, pavg, *initscore); | ||
return true; | ||
} | ||
|
||
private: | ||
/*! \brief Number of data points */ | ||
data_size_t num_data_; | ||
|
@@ -207,9 +230,24 @@ class CrossEntropyLambda: public ObjectiveFunction { | |
return str_buf.str(); | ||
} | ||
|
||
// might want to boost from a weighted average in general, if possible | ||
bool BoostFromAverage() const override { return true; } | ||
|
||
bool GetCustomAverage(double *initscore) const override { | ||
if (initscore == nullptr) return false; | ||
double sumy = 0.0f; | ||
for (data_size_t i = 0; i < num_data_; ++i) sumy += label_[i]; | ||
double sumw = 0.0f; | ||
if (weights_ == nullptr) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
olofer
Author
Contributor
|
||
for (data_size_t i = 0; i < num_data_; ++i) sumw += weights_[i]; | ||
} else { | ||
sumw = static_cast<double>(num_data_); | ||
} | ||
double havg = sumy / sumw; | ||
*initscore = std::log(std::exp(havg) - 1.0f); | ||
Log::Info("[%s:%s]: havg=%f -> initscore=%f", GetName(), __func__, havg, *initscore); | ||
return true; | ||
} | ||
|
||
private: | ||
/*! \brief Number of data points */ | ||
data_size_t num_data_; | ||
|
This also need to be fixed ~