Network { public void writeModel(BufferedWriter writer) throws IOException { writer.write("num_layers=" + getNumLayers()); writer.newLine(); writer.write("layer_sizes=" + Joiner.on(' ').join(layerSizes)); writer.newLine(); writer.write("w"); writer.newLine(); writer.newLine(); for (NinjaMatrix m : w) { for (int i = 0; i < m.numRows(); i++) { NinjaMatrix row = m.extractVector(true, i); writer.write(Joiner.on(' ').join(Doubles.asList(row.getData()))); writer.newLine(); } writer.newLine(); } } 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 testWriteModel() throws Exception { NinjaMatrix w1 = new NinjaMatrix(4, 4, true, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ); NinjaMatrix w2 = new NinjaMatrix(2, 5, true, 1, 2, 3, 4, 5, -6, -7, -8, -9, -10 ); Network net = new Network(w1, w2); StringWriter sw = new StringWriter(); BufferedWriter bw = new BufferedWriter(sw); net.writeModel(bw); bw.close(); Reader reader = new StringReader(sw.toString()); Network net2 = Network.loadModel(reader); assertTrue(w1.isIdentical(net2.getWeightMatrix(0), 0.00001)); assertTrue(w2.isIdentical(net2.getWeightMatrix(1), 0.00001)); }