Network { public ColVector apply(double... values) { return feedForward(values).a[getNumLayers() - 1]; } 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 testAnd() { NinjaMatrix w1 = new NinjaMatrix(1, 3, true, -15, 10, 10); Network net = new Network(w1); assertTrue(isZero(net.apply(0, 0))); assertTrue(isZero(net.apply(0, 1))); assertTrue(isZero(net.apply(1, 0))); assertTrue(isOne(net.apply(1, 1))); }
@Test public void testOr() { NinjaMatrix w1 = new NinjaMatrix(1, 3, true, -15, 20, 20); Network net = new Network(w1); assertTrue(isZero(net.apply(0, 0))); assertTrue(isOne(net.apply(0, 1))); assertTrue(isOne(net.apply(1, 0))); assertTrue(isOne(net.apply(1, 1))); }
@Test public void testNot() { NinjaMatrix w1 = new NinjaMatrix(1, 2, true, 5, -10); Network net = new Network(w1); assertTrue(isOne(net.apply(0))); assertTrue(isZero(net.apply(1))); }
@Test public void testNand() { NinjaMatrix w1 = new NinjaMatrix(1, 3, true, 15, -10, -10); Network net = new Network(w1); assertTrue(isOne(net.apply(0, 0))); assertTrue(isOne(net.apply(0, 1))); assertTrue(isOne(net.apply(1, 0))); assertTrue(isZero(net.apply(1, 1))); }
@Test public void testThreeLayerNand() { NinjaMatrix w1 = new NinjaMatrix(1, 3, true, -15, 10, 10); NinjaMatrix w2 = new NinjaMatrix(1, 2, true, 5, -10); Network net = new Network(w1, w2); assertTrue(isOne(net.apply(0, 0))); assertTrue(isOne(net.apply(0, 1))); assertTrue(isOne(net.apply(1, 0))); assertTrue(isZero(net.apply(1, 1))); }
@Test public void testFullThreeLayer() { NinjaMatrix w2 = new NinjaMatrix(4, 4, true, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ); NinjaMatrix w3 = new NinjaMatrix(2, 5, true, 1, 2, 3, 4, 5, -6, -7, -8, -9, -10 ); Network net = new Network(w2, w3); ColVector output = net.apply(1, 1, 1); assertEquals(2, output.numRows()); assertEquals(1, output.numCols()); assertEquals(1.0, output.get(0), 0.00001); assertEquals(0.0, output.get(1), 0.00001); }