MCPcopy Create free account
hub / github.com/catboost/catboost / CalcLogSoftmax

Function CalcLogSoftmax

catboost/libs/model/eval_processing.h:56–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54}
55
56inline void CalcLogSoftmax(const TConstArrayRef<double> approx, TArrayRef<double> logSoftmax) {
57 double maxApprox = *MaxElement(approx.begin(), approx.end());
58 for (size_t dim = 0; dim < approx.size(); ++dim) {
59 logSoftmax[dim] = approx[dim] - maxApprox;
60 }
61 NCB::FastExpWithInfInplace(logSoftmax.data(), logSoftmax.ysize());
62 double logSumExpApprox = 0;
63 for (auto curLogSoftmax : logSoftmax) {
64 logSumExpApprox += curLogSoftmax;
65 }
66 logSumExpApprox = std::log(logSumExpApprox);
67
68 for (size_t dim = 0; dim < approx.size(); ++dim) {
69 logSoftmax[dim] = approx[dim] - maxApprox - logSumExpApprox;
70 }
71}
72
73inline void CalcLogSoftmax(const TConstArrayRef<double> approx, TVector<double>* softmax) {
74 CalcLogSoftmax(approx, *softmax);

Callers

nothing calls this directly

Calls 8

MaxElementFunction · 0.85
FastExpWithInfInplaceFunction · 0.85
logFunction · 0.50
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45
ysizeMethod · 0.45

Tested by

no test coverage detected