public static double diffNormP1(DMatrixD1 a , DMatrixD1 b )
    {
        if( a.numRows != b.numRows || a.numCols != b.numCols ) {
            throw new IllegalArgumentException("Both matrices must have the same shape.");
        }

        final int size = a.getNumElements();

        double total=0;
        for( int i = 0; i < size; i++ ) {
            total += Math.abs(b.get(i) - a.get(i));
        }
        return total;
    }
public static double diffNormP1 ( DMatrixD1 a , DMatrixD1 b ) { if ( a . numRows != b . numRows || a . numCols != b . numCols ) { throw new IllegalArgumentException ( "Both matrices must have the same shape." ) ; } final int size = a . getNumElements ( ) ; double total = 0 ; for ( int i = 0 ; i < size ; i ++ ) { total += Math . abs ( b . get ( i ) - a . get ( i ) ) ; } return total ; }
<p>
Computes the p=1 p-norm of the difference between the two Matrices:<br>
<br>
&sum;<sub>i=1:m</sub> &sum;<sub>j=1:n</sub> | a<sub>ij</sub> - b<sub>ij</sub>| <br>
<br>
where |x| is the absolute value of x.
</p>
<p>
This is often used as a cost function.
</p>

@param a m by n matrix. Not modified.
@param b m by n matrix. Not modified.

@return The p=1 p-norm of the difference matrix.