-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdracula.softmax.js
More file actions
45 lines (40 loc) · 1018 Bytes
/
dracula.softmax.js
File metadata and controls
45 lines (40 loc) · 1018 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
function draculaSoftmax(values) {
// TODO: need to check if this U is the same as the one exported
var act = [];
for (var i = 0; i < values.length; i++) {
var tmp = numeric.dot(values[i], draculaParams_U);
tmp = numeric.add(tmp, draculaParams_b);
act.push(tmp);
}
var exp = [];
for (var i = 0; i < act.length; i++) {
var ex = numeric.exp(act[i]);
ex = numeric.div(ex, numeric.sum(ex))
exp.push(ex);
}
return exp;
}
function determineLabels(exp) {
// Compute the argmax
var ret = [];
for (var i = 0; i < exp.length; i++) {
var argMax = 0;
var argMaxVal = 0;
for (var j = 0; j < exp[i].length; j++) {
var v = exp[i][j];
if (v > argMaxVal) {
argMax = j;
argMaxVal = v;
}
}
if (argMax == 0) {
ret.push("negative");
} else if (argMax == 2) {
ret.push("positive");
} else {
ret.push("Something weird's going on here: the argMax is not working "
+" correctly");
}
}
return ret;
}