-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSigmoid.java
More file actions
executable file
·70 lines (56 loc) · 1.22 KB
/
Copy pathSigmoid.java
File metadata and controls
executable file
·70 lines (56 loc) · 1.22 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
public class Sigmoid
{
public static double sigmoid(double x)
{
double n = 1.0/(Math.exp(-x) + 1.0);
return n;
}
public static double[] arange(double start, double stop, double step)
{
double num_xs = (Math.abs(start)+Math.abs(stop))/step;
double[] xs = new double[(int)num_xs + 1];
int k = 0;
for ( double i = start; i < stop; i += step )
{
xs[k] = i;
k++;
}
return xs;
}
public static void plotGraph(double[] xs, double[] ys)
{
for (int i = 0; i < xs.length; i++)
{
double x = xs[i];
double y = ys[i];
StdDraw.setXscale(-10, 10);
StdDraw.setYscale(-1, 1);
StdDraw.setPenRadius(.005);
StdDraw.point(x, y);
}
}
public static double[] calculateSigmoidArray(double[] xs)
{
double[] a = new double[xs.length];
for ( int i = 0; i < xs.length; i++)
{
a[i] = sigmoid(xs[i]);
}
return a;
}
public static double[] calculateSineArray(double[] xs, double omega)
{
double[] b = new double[xs.length];
for ( int i = 0; i < xs.length; i++ )
{
b[i] = Math.sin(omega*xs[i]);
}
return b;
}
public static void main(String[] args)
{
double[] xs = arange(-10, 10, 0.1);
double[] ys = calculateSineArray(xs, 1);
plotGraph(xs, ys);
}
}