Network { public void randomInitialize() { for (int l = 0; l < getNumLayers() - 1; l++) { randomInitializeLayer(l); } } Network(NinjaMatrix ... w);  Network(List<Integer> layerSizes); void randomInitialize(); int getNumLayers(); int getNumUnits(int layer); NinjaMatrix getWeightMatrix(int layer); ColVector apply(double... values); ColVector apply(ColVector input); static List<Result> sort(ColVector vec); void trainBatch(ColVector[] x, ColVector[] y, double learningRate); static Network loadModel(File file); static Network loadModel(Reader reader); void writeModel(BufferedWriter writer); void writeModel(File file); @Override String toString();  }
@Test public void testRandomInitialize() { NinjaMatrix w1 = new NinjaMatrix(25, 401); NinjaMatrix w2 = new NinjaMatrix(10, 26); Network net = new Network(w1, w2); net.randomInitialize(); double epsilon = Math.sqrt(6) / Math.sqrt(400 + 25); NinjaMatrix m = net.getWeightMatrix(0); for (int i = 0; i < m.numRows(); i++) { for (int j = 0; j < m.numCols(); j++) { double weight = m.get(i, j); assertTrue(-epsilon <= weight && weight <= epsilon); } } epsilon = Math.sqrt(6) / Math.sqrt(25 + 10); m = net.getWeightMatrix(1); for (int i = 0; i < m.numRows(); i++) { for (int j = 0; j < m.numCols(); j++) { double weight = m.get(i, j); assertTrue(-epsilon <= weight && weight <= epsilon); } } }