-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeightMatrix.java
More file actions
48 lines (38 loc) · 1.32 KB
/
Copy pathWeightMatrix.java
File metadata and controls
48 lines (38 loc) · 1.32 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
import java.util.Random;
import java.lang.Math;
import java.util.*;
public class WeightMatrix{
Random rand = new Random();
public int input_layer;
public int next_layer;
public int weightsize;
public WeightMatrix(){}
//creates number of neurons for input and next layer
public WeightMatrix(int i, int n){
input_layer = i;
next_layer = n;
weightsize = input_layer * next_layer;
}
//create random weights based on number of input and output neurons in a layer
public double[][] createWeights(){
double [][] weights = new double [input_layer][next_layer];
for(int col = 0; col < weights[0].length; col++){
for(int row = 0; row < weights.length; row++){
weights[row][col] = Math.random() * 1 + 0;
}
}
return weights;
}
public void printWeights(double[][] w){
System.out.println("---------------Weight Matrix-----------");
System.out.println("{");
for(int row = 0; row< w.length; row++){
for(int col= 0; col < w[0].length; col++){
System.out.print(w[row][col]+ ", ");
}
System.out.println("");
System.out.println();
}
System.out.println("}");
}
}