Max-shift stabilised softmax. axis follows numpy: -1 (default) or
1 is row-wise for a matrix, 0 is column-wise. For a vector input the
full Jacobian diag(p) - p p^T is returned as well.
Examples
V <- c(1, 2, 3, 4, 5, 6, 7, 8)
morie_geron_softmax_function(V)
#> $p
#> [1] 0.0005766128 0.0015673960 0.0042606241 0.0115815771 0.0314819905
#> [6] 0.0855769227 0.2326221940 0.6323326828
#>
#> $probabilities
#> [1] 0.0005766128 0.0015673960 0.0042606241 0.0115815771 0.0314819905
#> [6] 0.0855769227 0.2326221940 0.6323326828
#>
#> $argmax
#> [1] 7
#>
#> $jacobian
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 5.762803e-04 -9.037806e-07 -2.456730e-06 -6.678085e-06 -1.815292e-05
#> [2,] -9.037806e-07 1.564939e-03 -6.678085e-06 -1.815292e-05 -4.934475e-05
#> [3,] -2.456730e-06 -6.678085e-06 4.242471e-03 -4.934475e-05 -1.341329e-04
#> [4,] -6.678085e-06 -1.815292e-05 -4.934475e-05 1.144744e-02 -3.646111e-04
#> [5,] -1.815292e-05 -4.934475e-05 -1.341329e-04 -3.646111e-04 3.049087e-02
#> [6,] -4.934475e-05 -1.341329e-04 -3.646111e-04 -9.911157e-04 -2.694132e-03
#> [7,] -1.341329e-04 -3.646111e-04 -9.911157e-04 -2.694132e-03 -7.323410e-03
#> [8,] -3.646111e-04 -9.911157e-04 -2.694132e-03 -7.323410e-03 -1.990709e-02
#> [,6] [,7] [,8]
#> [1,] -4.934475e-05 -0.0001341329 -0.0003646111
#> [2,] -1.341329e-04 -0.0003646111 -0.0009911157
#> [3,] -3.646111e-04 -0.0009911157 -0.0026941319
#> [4,] -9.911157e-04 -0.0026941319 -0.0073234097
#> [5,] -2.694132e-03 -0.0073234097 -0.0199070915
#> [6,] 7.825351e-02 -0.0199070915 -0.0541130851
#> [7,] -1.990709e-02 0.1785091089 -0.1470946160
#> [8,] -5.411309e-02 -0.1470946160 0.2324880611
#>
#> $estimate
#> [1] 0.6323327
#>
#> $n
#> [1] 8
#>
#> $method
#> [1] "Softmax with max-shift stabilisation (exact, not an approximation)"
#>
