forked from yusugomori/DeepLearning
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.java
More file actions
55 lines (43 loc) · 1.07 KB
/
utils.java
File metadata and controls
55 lines (43 loc) · 1.07 KB
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
46
47
48
49
50
51
52
53
54
55
package DeepLearning;
import java.util.Random;
public class utils {
public static double uniform(double min, double max, Random rng) {
return rng.nextDouble() * (max - min) + min;
}
public static int binomial(int n, double p, Random rng) {
if(p < 0 || p > 1) return 0;
int c = 0;
double r;
for(int i=0; i<n; i++) {
r = rng.nextDouble();
if (r < p) c++;
}
return c;
}
public static double sigmoid(double x) {
return 1. / (1. + Math.pow(Math.E, -x));
}
public static double dsigmoid(double x) {
return x * (1. - x);
}
public static double tanh(double x) {
return Math.tanh(x);
}
public static double dtanh(double x) {
return 1. - x * x;
}
public static double ReLU(double x) {
if(x > 0) {
return x;
} else {
return 0.;
}
}
public static double dReLU(double x) {
if(x > 0) {
return 1.;
} else {
return 0.;
}
}
}