NNFactory.lcMaxPooling(nn);
// feedforwad cc
LayerCalculatorImpl lc = (LayerCalculatorImpl) nn.getLayerCalculator();
Layer l = nn.getInputLayer();
assertTrue(lc.getConnectionCalculator(l) instanceof ConnectionCalculatorConv);
l = l.getConnections().get(0).getOutputLayer();
assertTrue(lc.getConnectionCalculator(l) instanceof ConnectionCalculatorConv);
l = l.getConnections().get(2).getOutputLayer();
assertTrue(lc.getConnectionCalculator(l) instanceof AparapiMaxPooling2D);
l = l.getConnections().get(1).getOutputLayer();
assertTrue(lc.getConnectionCalculator(l) instanceof ConnectionCalculatorConv);
l = l.getConnections().get(2).getOutputLayer();
assertTrue(lc.getConnectionCalculator(l) instanceof AparapiMaxPooling2D);
l = l.getConnections().get(1).getOutputLayer();
assertTrue(lc.getConnectionCalculator(l) instanceof ConnectionCalculatorFullyConnected);
l = l.getConnections().get(2).getOutputLayer();
assertTrue(lc.getConnectionCalculator(l) instanceof ConnectionCalculatorFullyConnected);
// backpropagation cc
BackPropagationTrainer<?> bpt = TrainerFactory.backPropagation(nn, null, null, null, null, 0.01f, 0.5f, 0f, 0f, 0f, 1, 1, 1);
BackPropagationLayerCalculatorImpl bplc = (BackPropagationLayerCalculatorImpl) bpt.getBPLayerCalculator();
l = nn.getInputLayer();
assertTrue(bplc.getConnectionCalculator(l) instanceof BackPropagationConv2DSigmoid);
l = l.getConnections().get(0).getOutputLayer();
assertTrue(bplc.getConnectionCalculator(l) instanceof BackpropagationMaxPooling2D);
assertTrue(bplc.getConnectionCalculator(l.getConnections().get(1).getInputLayer()) instanceof BackPropagationConv2D); // bias
l = l.getConnections().get(2).getOutputLayer();
assertTrue(bplc.getConnectionCalculator(l) instanceof BackPropagationConv2DSigmoid);
l = l.getConnections().get(1).getOutputLayer();
assertTrue(bplc.getConnectionCalculator(l) instanceof BackpropagationMaxPooling2D);
assertTrue(bplc.getConnectionCalculator(l.getConnections().get(1).getInputLayer()) instanceof BackPropagationConv2D);
l = l.getConnections().get(2).getOutputLayer();
assertTrue(bplc.getConnectionCalculator(l) instanceof BackPropagationSigmoid);
l = l.getConnections().get(1).getOutputLayer();
assertTrue(bplc.getConnectionCalculator(l.getConnections().get(1).getInputLayer()) instanceof BackPropagationSigmoid);
assertTrue(bplc.getConnectionCalculator(l) instanceof BackPropagationSigmoid);
l = l.getConnections().get(2).getOutputLayer();
assertTrue(bplc.getConnectionCalculator(l.getConnections().get(1).getInputLayer()) instanceof BackPropagationSigmoid);
assertTrue(bplc.getConnectionCalculator(l) == null);
// simple convolutional network
Environment.getInstance().setUseWeightsSharedMemory(true);
nn = NNFactory.convNN(new int[][] { { 28, 28, 1 }, { 1, 1 }, {10} }, false);
nn.setLayerCalculator(NNFactory.lcSigmoid(nn, null));
NNFactory.lcMaxPooling(nn);
l = nn.getInputLayer();
assertTrue(lc.getConnectionCalculator(l) instanceof ConnectionCalculatorConv);
l = l.getConnections().get(0).getOutputLayer();
assertTrue(lc.getConnectionCalculator(l) instanceof AparapiSubsampling2D);
l = l.getConnections().get(0).getOutputLayer();
assertTrue(lc.getConnectionCalculator(l) instanceof AparapiSigmoid);
bpt = TrainerFactory.backPropagation(nn, null, null, new MultipleNeuronsOutputError(), null, 0.02f, 0.5f, 0f, 0f, 0f, 1, 1, 1);
bplc = (BackPropagationLayerCalculatorImpl) bpt.getBPLayerCalculator();
l = nn.getInputLayer();
assertTrue(lc.getConnectionCalculator(l) instanceof BackpropagationMaxPooling2D);
l = l.getConnections().get(0).getOutputLayer();
assertTrue(lc.getConnectionCalculator(l) instanceof BackPropagationSigmoid);
}