src/main/java/convnet/Data.java
/**
     * Returns a 3d slice of the data for operation.
     * @param sliceHeightPair
     * @param sliceWidthPair
     * @param sliceDepthPair
     * @return slice
     */
Returns a 3d slice of the data for operation.
Returns a 3d slice of the data for operation .
public double[][][] slice3d(int[] sliceHeightPair, int[] sliceWidthPair, int[] sliceDepthPair) {
        int sliceH = sliceHeightPair[1] - sliceHeightPair[0];
        int sliceW = sliceWidthPair[1] - sliceWidthPair[0];
        int sliceD = sliceDepthPair[1] - sliceDepthPair[0];
        double[][][] slice = new double[sliceH][sliceW][sliceD];
        if (data3d == null) {
            throw new RuntimeException("No data to slice.");
        } else if (sliceHeightPair[1] < sliceHeightPair[0] ||
                sliceWidthPair[1] < sliceWidthPair[0] ||
                sliceDepthPair[1] < sliceDepthPair[0]) {
            throw new RuntimeException("Malformed pairs.");
        } else if (sliceHeightPair[1] > dimensions[0] ||
                sliceWidthPair[1] > dimensions[1] ||
                sliceDepthPair[1] > dimensions[2]) {
            throw new RuntimeException("Slice exceeds dimensions.");
        } else {
            for (int i = 0; i < sliceH; i++) {
                for (int j = 0; j < sliceW; j++) {
                    for (int k = 0; k < sliceD; k++) {
                        int coordI = sliceHeightPair[0] + i;
                        int coordJ = sliceHeightPair[0] + j;
                        int coordK = sliceHeightPair[0] + k;
                        slice[coordI][coordJ][coordK] = data3d[coordI][coordJ][coordK];
                    }
                }
            }
        }
        return slice;
    }
public double [ ] [ ] [ ] slice3d ( int [ ] sliceHeightPair , int [ ] sliceWidthPair , int [ ] sliceDepthPair ) { int sliceH = sliceHeightPair [ 1 ] - sliceHeightPair [ 0 ] ; int sliceW = sliceWidthPair [ 1 ] - sliceWidthPair [ 0 ] ; int sliceD = sliceDepthPair [ 1 ] - sliceDepthPair [ 0 ] ; double [ ] [ ] [ ] slice = new double [ sliceH ] [ sliceW ] [ sliceD ] ; if ( data3d == null ) { throw new RuntimeException ( "No data to slice." ) ; } else if ( sliceHeightPair [ 1 ] < sliceHeightPair [ 0 ] || sliceWidthPair [ 1 ] < sliceWidthPair [ 0 ] || sliceDepthPair [ 1 ] < sliceDepthPair [ 0 ] ) { throw new RuntimeException ( "Malformed pairs." ) ; } else if ( sliceHeightPair [ 1 ] > dimensions [ 0 ] || sliceWidthPair [ 1 ] > dimensions [ 1 ] || sliceDepthPair [ 1 ] > dimensions [ 2 ] ) { throw new RuntimeException ( "Slice exceeds dimensions." ) ; } else { for ( int i = 0 ; i < sliceH ; i ++ ) { for ( int j = 0 ; j < sliceW ; j ++ ) { for ( int k = 0 ; k < sliceD ; k ++ ) { int coordI = sliceHeightPair [ 0 ] + i ; int coordJ = sliceHeightPair [ 0 ] + j ; int coordK = sliceHeightPair [ 0 ] + k ; slice [ coordI ] [ coordJ ] [ coordK ] = data3d [ coordI ] [ coordJ ] [ coordK ] ; } } } } return slice ; }
Returns a 3d slice of the data for operation.
Returns a 3d slice of the data for operation .