This is an old version, view current version.

5.11 Special Matrix Functions

5.11.1 Softmax

The softmax function maps3 yRK to the K-simplex by softmax(y)=exp(y)Kk=1exp(yk), where exp(y) is the componentwise exponentiation of y. Softmax is usually calculated on the log scale, logsoftmax(y)= ylogKk=1exp(yk)=ylog_sum_exp(y). where the vector y minus the scalar log_sum_exp(y) subtracts the scalar from each component of y.

Stan provides the following functions for softmax and its log.

vector softmax(vector x)
The softmax of x

vector log_softmax(vector x)
The natural logarithm of the softmax of x

5.11.2 Cumulative Sums

The cumulative sum of a sequence x1,,xN is the sequence y1,,yN, where yn=nm=1xm.

real[] cumulative_sum(real[] x)
The cumulative sum of x

vector cumulative_sum(vector v)
The cumulative sum of v

row_vector cumulative_sum(row_vector rv)
The cumulative sum of rv