src/core/layer/normalization/BatchNormalization.java
public void forwardProcess() throws MatrixException, DynamicParamException {
        resetLayer();
        Sequence inputSequence = getPreviousLayerOutputs();

        if (isTraining()) {
            if (batchSize == -1) batchSize = inputSequence.sampleSize();
            if (inputSequence.sampleSize() < 2) throw new MatrixException("Batch normalization must have minimum batch size of 2 for training phase.");

            procedure.calculateExpression(inputSequence, getLayerOutputs());

            averageMean = meanNode.getMatrix().exponentialMovingAverage(averageMean, momentum);
            if (!meanOnly) averageVariance = varianceNode.getMatrix().exponentialMovingAverage(averageVariance, momentum);
        }
        else {
            if (!meanOnly) {
                Matrix averageStandardDeviation = averageVariance.multiply(batchSize / (batchSize - 1)).add(epsilonMatrix).apply(UnaryFunctionType.SQRT);
                for (Integer sampleIndex : inputSequence.keySet()) {
                    for (Integer entryIndex : inputSequence.get(sampleIndex).keySet()) {
                        getLayerOutputs().put(sampleIndex, entryIndex, inputSequence.get(sampleIndex, entryIndex).subtract(averageMean).divide(averageStandardDeviation).multiply(weightSet.gamma).add(weightSet.beta));
                    }
                }
            }
            else {
                for (Integer sampleIndex : inputSequence.keySet()) {
                    for (Integer entryIndex : inputSequence.get(sampleIndex).keySet()) {
                        getLayerOutputs().put(sampleIndex, entryIndex, inputSequence.get(sampleIndex, entryIndex).subtract(averageMean).multiply(weightSet.gamma).add(weightSet.beta));
                    }
                }
            }
        }
    }
/**
     * Takes single forward processing step to process layer input(s).<br>
     *
     * @throws MatrixException throws exception if matrix operation fails.
     * @throws DynamicParamException throws exception if parameter (params) setting fails.
     */
Takes single forward processing step to process layer input(s).

@throws MatrixException throws exception if matrix operation fails.
@throws DynamicParamException throws exception if parameter (params) setting fails.
Takes single forward processing step to process layer input ( s ) . @throws MatrixException throws exception if matrix operation fails . @throws DynamicParamException throws exception if parameter ( params ) setting fails .
public void forwardProcess() throws MatrixException, DynamicParamException {
        resetLayer();
        Sequence inputSequence = getPreviousLayerOutputs();
        if (isTraining()) {
            if (batchSize == -1) batchSize = inputSequence.sampleSize();
            if (inputSequence.sampleSize() < 2) throw new MatrixException("Batch normalization must have minimum batch size of 2 for training phase.");
            procedure.calculateExpression(inputSequence, getLayerOutputs());
            averageMean = meanNode.getMatrix().exponentialMovingAverage(averageMean, momentum);
            if (!meanOnly) averageVariance = varianceNode.getMatrix().exponentialMovingAverage(averageVariance, momentum);
        }
        else {
            if (!meanOnly) {
                Matrix averageStandardDeviation = averageVariance.multiply(batchSize / (batchSize - 1)).add(epsilonMatrix).apply(UnaryFunctionType.SQRT);
                for (Integer sampleIndex : inputSequence.keySet()) {
                    for (Integer entryIndex : inputSequence.get(sampleIndex).keySet()) {
                        getLayerOutputs().put(sampleIndex, entryIndex, inputSequence.get(sampleIndex, entryIndex).subtract(averageMean).divide(averageStandardDeviation).multiply(weightSet.gamma).add(weightSet.beta));
                    }
                }
            }
            else {
                for (Integer sampleIndex : inputSequence.keySet()) {
                    for (Integer entryIndex : inputSequence.get(sampleIndex).keySet()) {
                        getLayerOutputs().put(sampleIndex, entryIndex, inputSequence.get(sampleIndex, entryIndex).subtract(averageMean).multiply(weightSet.gamma).add(weightSet.beta));
                    }
                }
            }
        }
    }
public void forwardProcess ( ) throws MatrixException , DynamicParamException { resetLayer ( ) ; Sequence inputSequence = getPreviousLayerOutputs ( ) ; if ( isTraining ( ) ) { if ( batchSize == - 1 ) batchSize = inputSequence . sampleSize ( ) ; if ( inputSequence . sampleSize ( ) < 2 ) throw new MatrixException ( "Batch normalization must have minimum batch size of 2 for training phase." ) ; procedure . calculateExpression ( inputSequence , getLayerOutputs ( ) ) ; averageMean = meanNode . getMatrix ( ) . exponentialMovingAverage ( averageMean , momentum ) ; if ( ! meanOnly ) averageVariance = varianceNode . getMatrix ( ) . exponentialMovingAverage ( averageVariance , momentum ) ; } else { if ( ! meanOnly ) { Matrix averageStandardDeviation = averageVariance . multiply ( batchSize / ( batchSize - 1 ) ) . add ( epsilonMatrix ) . apply ( UnaryFunctionType . SQRT ) ; for ( Integer sampleIndex : inputSequence . keySet ( ) ) { for ( Integer entryIndex : inputSequence . get ( sampleIndex ) . keySet ( ) ) { getLayerOutputs ( ) . put ( sampleIndex , entryIndex , inputSequence . get ( sampleIndex , entryIndex ) . subtract ( averageMean ) . divide ( averageStandardDeviation ) . multiply ( weightSet . gamma ) . add ( weightSet . beta ) ) ; } } } else { for ( Integer sampleIndex : inputSequence . keySet ( ) ) { for ( Integer entryIndex : inputSequence . get ( sampleIndex ) . keySet ( ) ) { getLayerOutputs ( ) . put ( sampleIndex , entryIndex , inputSequence . get ( sampleIndex , entryIndex ) . subtract ( averageMean ) . multiply ( weightSet . gamma ) . add ( weightSet . beta ) ) ; } } } } }
Takes single forward processing step to process layer input(s).<br>
Takes single forward processing step to process layer input ( s ) . <br >