MCPcopy Create free account
hub / github.com/EdwardRaff/JSAT / softmax

Method softmax

JSAT/src/jsat/math/MathTricks.java:91–102  ·  view source on GitHub ↗

Applies the softmax function to the given array of values, normalizing them so that each value is equal to exp(x j ) / Σ ∀ i exp(x i ) @param x the array of values @param implicitExtra true if the softmax will assume there is an extra implici

(double[] x, boolean implicitExtra)

Source from the content-addressed store, hash-verified

89 * an extra implicit value not included in the array with a value of 0.0
90 */
91 public static void softmax(double[] x, boolean implicitExtra)
92 {
93 double max = implicitExtra ? 1 : Double.NEGATIVE_INFINITY;
94 for(int i = 0; i < x.length; i++)
95 max = max(max, x[i]);
96
97 double z =implicitExtra ? exp(-max) : 0;
98 for (int c = 0; c < x.length; c++)
99 z += (x[c] = exp(x[c] - max));
100 for (int c = 0; c < x.length; c++)
101 x[c] /= z;
102 }
103
104 /**
105 * Applies the softmax function to the given array of values, normalizing

Callers 7

processMethod · 0.95
classifyMethod · 0.95
classifyMethod · 0.95
trainCMethod · 0.95
activateMethod · 0.95

Calls 6

maxMethod · 0.95
expMethod · 0.80
lengthMethod · 0.45
getMethod · 0.45
setMethod · 0.45
mutableDivideMethod · 0.45

Tested by 2