matrices[0] = new DenseDoubleMatrix(5, 3, 0.2);
matrices[1] = new DenseDoubleMatrix(1, 6, 0.8);
ann.setWeightMatrices(matrices);
ann.setLearningStyle(LearningStyle.UNSUPERVISED);
FeatureTransformer defaultFeatureTransformer = new DefaultFeatureTransformer();
ann.setFeatureTransformer(defaultFeatureTransformer);
// write to file
String modelPath = "/tmp/testSmallLayeredNeuralNetworkReadWrite";
ann.setModelPath(modelPath);
try {
ann.writeModelToFile();
} catch (IOException e) {
e.printStackTrace();
}
// read from file
SmallLayeredNeuralNetwork annCopy = new SmallLayeredNeuralNetwork(modelPath);
assertEquals(annCopy.getClass().getSimpleName(), annCopy.getModelType());
assertEquals(modelPath, annCopy.getModelPath());
assertEquals(learningRate, annCopy.getLearningRate(), 0.000001);
assertEquals(momentumWeight, annCopy.getMomemtumWeight(), 0.000001);
assertEquals(regularizationWeight, annCopy.getRegularizationWeight(),
0.000001);
assertEquals(TrainingMethod.GRADIENT_DESCENT, annCopy.getTrainingMethod());
assertEquals(LearningStyle.UNSUPERVISED, annCopy.getLearningStyle());
// compare weights
DoubleMatrix[] weightsMatrices = annCopy.getWeightMatrices();
for (int i = 0; i < weightsMatrices.length; ++i) {
DoubleMatrix expectMat = matrices[i];
DoubleMatrix actualMat = weightsMatrices[i];
for (int j = 0; j < expectMat.getRowCount(); ++j) {
for (int k = 0; k < expectMat.getColumnCount(); ++k) {
assertEquals(expectMat.get(j, k), actualMat.get(j, k), 0.000001);
}
}
}
FeatureTransformer copyTransformer = annCopy.getFeatureTransformer();
assertEquals(defaultFeatureTransformer.getClass().getName(), copyTransformer.getClass().getName());
}