Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed
4 years ago
.
Folks,
Are there any example of the implementation of a simple softmax function for N values? I've seem things like "softmax-based detectors" and so forth, but I just want to see a pure, straightforward C++ softmax implementation.
Any examples you know of?
Thanks,
–
–
–
I haven't seen a library implementation of softmax, although that's not proof that it doesn't exist. It's simple enough that people just write their own when they need it.
For the record, the softmax function on
u1
,
u2
,
u3
... is just the tuple
(exp(u1)/Z, exp(u2)/Z, exp(u3)/Z, ...)
where the normalizing constant
Z
is just the sum of the exponentials,
Z = exp(u1) + exp(u2) + exp(u3) + ...
.
Note that adding or subtracting a constant from each
u
leaves the result unchanged, since it's equivalent to multiplying above and below by the same factor. So you could make the calculation a little more numerically well-behaved by subtracting the greatest value among the
u
's; then the largest term
exp(u)
will be 1 and all the others something smaller than that.