src/main/java/convnet/CNN.java
/**
     * Logic for backpropagation on a convolutional layer.
     * @param layer
     * @param nextLayer
     */
Logic for backpropagation on a convolutional layer.
@param layer
@param nextLayer
Logic for backpropagation on a convolutional layer . @param layer @param nextLayer
private void backpropagateConv(Layer layer, Layer nextLayer) {
        Data currLayerOutput = layer.getLayerOutput();
        int cm = currLayerOutput.getDimensions()[0];
        int cn = currLayerOutput.getDimensions()[1];
        int co = currLayerOutput.getDimensions()[2];
        int nErrLength = nextLayer.getLayerErrorsLength();
        if (co != nErrLength) {
            throw new RuntimeException("Backprop error: mismatched layer outputs vs nextLayer inputs");
        }
        for (int i = 0; i < co; i++) {
            int[] ch = new int[]{0, cm};
            int[] cw = new int[]{0, cn};
            int[] cd = new int[]{i, i + 1};
            double[][] cOutputMap = currLayerOutput.slice3d(ch, cw, cd)[0];
            double[][] nErrorMap = nextLayer.getLayerErrorByIndex(i).read2d();
            for (int k = 0; k < layer.getKernelsLength(); k++) {
                Data kernel = layer.getKernelByIndex(k);
                double bias = layer.getBiasByIndex(k);
                Data input = layer.getLayerInput();
                Data activationMap = this.evalValidConvolution(input, kernel, bias);
            }
        }
    }
private void backpropagateConv ( Layer layer , Layer nextLayer ) { Data currLayerOutput = layer . getLayerOutput ( ) ; int cm = currLayerOutput . getDimensions ( ) [ 0 ] ; int cn = currLayerOutput . getDimensions ( ) [ 1 ] ; int co = currLayerOutput . getDimensions ( ) [ 2 ] ; int nErrLength = nextLayer . getLayerErrorsLength ( ) ; if ( co != nErrLength ) { throw new RuntimeException ( "Backprop error: mismatched layer outputs vs nextLayer inputs" ) ; } for ( int i = 0 ; i < co ; i ++ ) { int [ ] ch = new int [ ] { 0 , cm } ; int [ ] cw = new int [ ] { 0 , cn } ; int [ ] cd = new int [ ] { i , i + 1 } ; double [ ] [ ] cOutputMap = currLayerOutput . slice3d ( ch , cw , cd ) [ 0 ] ; double [ ] [ ] nErrorMap = nextLayer . getLayerErrorByIndex ( i ) . read2d ( ) ; for ( int k = 0 ; k < layer . getKernelsLength ( ) ; k ++ ) { Data kernel = layer . getKernelByIndex ( k ) ; double bias = layer . getBiasByIndex ( k ) ; Data input = layer . getLayerInput ( ) ; Data activationMap = this . evalValidConvolution ( input , kernel , bias ) ; } } }
Logic for backpropagation on a convolutional layer.
Logic for backpropagation on a convolutional layer .