I would like to plot the softmax activiation function. I know that there is already a similar question but unfortunately neither the comments, nor the answer provided there could really help me so far. This is my current code:
\begin{figure}[t]
\begin{tikzpicture}
\begin{axis}[
ylabel=$\sigma(z)_j$,
xlabel=$z$,
xmin=-5,
xmax=5]
\addplot[blue,domain=-5:5,samples=51]
{exp(x)/sumexp(x,-4,0)};
\end{axis}
\end{tikzpicture}
\caption{Softmax activation function.}
\end{figure}
Attempting to compile this code always results in the following error message:
Package PGF Math Error: Unknown function `sumexp' (in 'exp(x)/sumexp(x,-4,0)'). \end{tikzpicture} }
Any ideas are highly appreciated.
//edit:
After adding the following definition (that I foolishly forgot to add before):
\pgfmathdeclarefunction{sumexp}{3}{%
\begingroup%
\pgfkeys{/pgf/fpu,/pgf/fpu/output format=fixed}%
\pgfmathsetmacro{\myx}{#1}%
\pgfmathtruncatemacro{\myxmin}{#2}%
\pgfmathtruncatemacro{\myxmax}{#3}%
\pgfmathsetmacro{\mysum}{0}%
\pgfplotsforeachungrouped\XX in {\myxmin,...,\myxmax}%
{\pgfmathsetmacro{\mysum}{\mysum+exp(\XX)}}%
\pgfmathparse{\mysum+exp(#1)}%
\pgfmathsmuggle\pgfmathresult\endgroup%
}%
I end up with the following error message:
Package PGF Math Error: Sorry, an internal routine of the floating point unitt was near '-4.0000000000'. (in 'exp(x)/sumexp(x,-4,0)'). \end{tikzpicture} }
