src/core/optimization/NesterovAcceleratedGradient.java
public void optimize(Matrix matrix, Matrix matrixGradient) throws MatrixException {
        if (dPrev == null) dPrev = new HashMap<>();
        if (vPrev == null) vPrev = new HashMap<>();
        Matrix dMPrev;
        if (dPrev.containsKey(matrix)) dMPrev = dPrev.get(matrix);
        else dPrev.put(matrix, dMPrev = new DMatrix(matrix.getRows(), matrix.getColumns()));

        Matrix vMPrev;
        if (vPrev.containsKey(matrix)) vMPrev = dPrev.get(matrix);
        else vPrev.put(matrix, vMPrev = new DMatrix(matrix.getRows(), matrix.getColumns()));

        // vt=μvt−1−ϵ∇f(θt−1+μvt−1)
        Matrix vM = vMPrev.multiply(mu).subtract(dMPrev.add(vMPrev.multiply(mu)).multiply(learningRate));

        matrix.add(vM, matrix);

        vPrev.put(matrix, vM);
        dPrev.put(matrix, matrixGradient);

    }
/**
     * Optimizes single matrix (M) using calculated matrix gradient (dM).<br>
     * Matrix can be for example weight or bias matrix with gradient.<br>
     *
     * @param matrix matrix to be optimized.
     * @param matrixGradient matrix gradients for optimization step.
     * @throws MatrixException throws exception if matrix operation fails.
     */
Optimizes single matrix (M) using calculated matrix gradient (dM).
Matrix can be for example weight or bias matrix with gradient.

@param matrix matrix to be optimized.
@param matrixGradient matrix gradients for optimization step.
@throws MatrixException throws exception if matrix operation fails.
Optimizes single matrix ( M ) using calculated matrix gradient ( dM ) . Matrix can be for example weight or bias matrix with gradient . @param matrix matrix to be optimized . @param matrixGradient matrix gradients for optimization step . @throws MatrixException throws exception if matrix operation fails .
public void optimize(Matrix matrix, Matrix matrixGradient) throws MatrixException {
        if (dPrev == null) dPrev = new HashMap<>();
        if (vPrev == null) vPrev = new HashMap<>();
        Matrix dMPrev;
        if (dPrev.containsKey(matrix)) dMPrev = dPrev.get(matrix);
        else dPrev.put(matrix, dMPrev = new DMatrix(matrix.getRows(), matrix.getColumns()));
        Matrix vMPrev;
        if (vPrev.containsKey(matrix)) vMPrev = dPrev.get(matrix);
        else vPrev.put(matrix, vMPrev = new DMatrix(matrix.getRows(), matrix.getColumns()));
        Matrix vM = vMPrev.multiply(mu).subtract(dMPrev.add(vMPrev.multiply(mu)).multiply(learningRate));
        matrix.add(vM, matrix);
        vPrev.put(matrix, vM);
        dPrev.put(matrix, matrixGradient);
    }
public void optimize ( Matrix matrix , Matrix matrixGradient ) throws MatrixException { if ( dPrev == null ) dPrev = new HashMap < > ( ) ; if ( vPrev == null ) vPrev = new HashMap < > ( ) ; Matrix dMPrev ; if ( dPrev . containsKey ( matrix ) ) dMPrev = dPrev . get ( matrix ) ; else dPrev . put ( matrix , dMPrev = new DMatrix ( matrix . getRows ( ) , matrix . getColumns ( ) ) ) ; Matrix vMPrev ; if ( vPrev . containsKey ( matrix ) ) vMPrev = dPrev . get ( matrix ) ; else vPrev . put ( matrix , vMPrev = new DMatrix ( matrix . getRows ( ) , matrix . getColumns ( ) ) ) ; Matrix vM = vMPrev . multiply ( mu ) . subtract ( dMPrev . add ( vMPrev . multiply ( mu ) ) . multiply ( learningRate ) ) ; matrix . add ( vM , matrix ) ; vPrev . put ( matrix , vM ) ; dPrev . put ( matrix , matrixGradient ) ; }
Optimizes single matrix (M) using calculated matrix gradient (dM).<br>
 Matrix can be for example weight or bias matrix with gradient.<br>
Optimizes single matrix ( M ) using calculated matrix gradient ( dM ) . <br > Matrix can be for example weight or bias matrix with gradient . <br >
// vt=μvt−1−ϵ∇f(θt−1+μvt−1)