MCPcopy Create free account
hub / github.com/antmachineintelligence/mtgbmcode / Softmax

Function Softmax

include/LightGBM/utils/common.h:602–616  ·  view source on GitHub ↗

! * \brief Do inplace softmax transformation on p_rec * \param p_rec The input/output vector of the values. */

Source from the content-addressed store, hash-verified

600 * \param p_rec The input/output vector of the values.
601 */
602inline static void Softmax(std::vector<double>* p_rec) {
603 std::vector<double> &rec = *p_rec;
604 double wmax = rec[0];
605 for (size_t i = 1; i < rec.size(); ++i) {
606 wmax = std::max(rec[i], wmax);
607 }
608 double wsum = 0.0f;
609 for (size_t i = 0; i < rec.size(); ++i) {
610 rec[i] = std::exp(rec[i] - wmax);
611 wsum += rec[i];
612 }
613 for (size_t i = 0; i < rec.size(); ++i) {
614 rec[i] /= static_cast<double>(wsum);
615 }
616}
617
618inline static void Softmax(const double* input, double* output, int len) {
619 double wmax = input[0];

Callers 2

GetGradientsMethod · 0.50
ConvertOutputMethod · 0.50

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected