-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeedForward.java
63 lines (56 loc) · 1.46 KB
/
feedForward.java
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
import java.util.Random;
public class feedForward {
public static Double [] multiplyMatrixVector(Double[][] mat ,Double[] vector)
{
Double []result=new Double [mat.length];
Double sum=0.0;
for(int i =0 ;i<mat.length ;i++)
{
for(int k=0;k<mat[0].length;k++)
{
sum+=mat[i][k]*vector[k];
}
result[i]=sum;
sum=0.0;
}
return result;
}
public static double randomFloat(double min,double max)
{
Random rand = new Random();
return (double) (rand.nextDouble()* (max - min) + min);
}
public static void initializeWeights()
{
for(int i=0;i<Main.L;i++)
{
for(int j=0;j<Main.M;j++)
Main.Wh[i][j]=randomFloat(-5.0,5.0);
}
for(int i=0;i<Main.N;i++)
{
for(int j=0;j<Main.L;j++)
Main.Wo[i][j]=randomFloat(-5.0,5.0);
}
}
public static Double [] sigmoidFunction(Double [] Arr)
{
Double [] I =new Double [Arr.length];
for(int i=0;i<Arr.length;i++)
{
I[i]=(1/(1+Math.exp(-Arr[i])));
}
return I;
}
public static void FeedAlgorithm(int index)
{
//compute net-input to hidden layer
Double [] net_h=multiplyMatrixVector(Main.Wh ,Main.xValues.get(index));
//compute net-output of hidden layer
backPropagate.I =sigmoidFunction(net_h);
//compute net-input to output layer
Double [] net_o=multiplyMatrixVector(Main.Wo ,backPropagate.I);
//compute net-output of output layer
backPropagate.outputK=sigmoidFunction(net_o);
}
}