public static Matrix identity(int size) { Matrix result = new Matrix(size, size); CommonOps.setIdentity(result.mat); return result; }
/** * @param matrix The matrix to return as a String * @param format The format to use for each value in the matrix, eg "%f" */ public static String toString(SimpleMatrix matrix, String format) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); MatrixIO.print(new PrintStream(stream), matrix.getMatrix(), format); return stream.toString(); }
public synchronized void setMatrix( D1Matrix64F A ) { double maxValue = CommonOps.elementMaxAbs(A); renderMatrix(A,image,maxValue); repaint(); }
public static double quality( DenseMatrix64F orig , DenseMatrix64F U , DenseMatrix64F W , DenseMatrix64F Vt ) { // foundA = U*W*Vt DenseMatrix64F UW = new DenseMatrix64F(U.numRows,W.numCols); CommonOps.mult(U,W,UW); DenseMatrix64F foundA = new DenseMatrix64F(UW.numRows,Vt.numCols); CommonOps.mult(UW,Vt,foundA); double normA = NormOps.normF(foundA); return SpecializedOps.diffNormF(orig,foundA)/normA; }
/** * Computes the p=∞ norm. If A is a matrix then the induced norm is computed. * * @param A Matrix or vector. * @return The norm. */ public static double normPInf( DenseMatrix64F A ) { if( MatrixFeatures.isVector(A)) { return CommonOps.elementMaxAbs(A); } else { return inducedPInf(A); } }
/** * Computes the p=1 norm. If A is a matrix then the induced norm is computed. * * @param A Matrix or vector. * @return The norm. */ public static double normP1( DenseMatrix64F A ) { if( MatrixFeatures.isVector(A)) { return CommonOps.elementSumAbs(A); } else { return inducedP1(A); } }
/** * Computes the p=2 norm. If A is a matrix then the induced norm is computed. This * implementation is faster, but more prone to buffer overflow or underflow problems. * * @param A Matrix or vector. * @return The norm. */ public static double fastNormP2( DenseMatrix64F A ) { if( MatrixFeatures.isVector(A)) { return fastNormF(A); } else { return inducedP2(A); } }
/** * <p> * Sets each element in the matrix to a value drawn from an uniform distribution from 0 to 1 inclusive. * </p> * * @param mat The matrix who is to be randomized. Modified. * @param rand Random number generator used to fill the matrix. */ public static void setRandom( DenseMatrix64F mat , Random rand ) { setRandom(mat,0,1,rand); }
/** * Computes the nullity of a matrix using the default tolerance. * * @param A Matrix whose rank is to be calculated. Not modified. * @return The matrix's nullity. */ public static int nullity( DenseMatrix64F A ) { return nullity(A, UtilEjml.EPS*100); }
/** * This is a fairly light weight check to see of a covariance matrix is valid. * It checks to see if the diagonal elements are all positive, which they should be * if it is valid. Not all invalid covariance matrices will be caught by this method. * * @return true if valid and false if invalid */ public static boolean isValidFast( DenseMatrix64F cov ) { return MatrixFeatures.isDiagonalPositive(cov); }
/** * Computes the p=∞ norm. If A is a matrix then the induced norm is computed. * * @param A Matrix or vector. * @return The norm. */ public static double normPInf( DenseMatrix64F A ) { if( MatrixFeatures.isVector(A)) { return CommonOps.elementMaxAbs(A); } else { return inducedPInf(A); } }
public synchronized void setMatrix( D1Matrix64F A ) { double maxValue = CommonOps.elementMaxAbs(A); renderMatrix(A,image,maxValue); repaint(); }
/** * Computes the p=1 norm. If A is a matrix then the induced norm is computed. * * @param A Matrix or vector. * @return The norm. */ public static double normP1( DenseMatrix64F A ) { if( MatrixFeatures.isVector(A)) { return CommonOps.elementSumAbs(A); } else { return inducedP1(A); } }
@Override public void print() { MatrixIO.print(System.out, this); } }
/** * Computes the p=∞ norm. If A is a matrix then the induced norm is computed. * * @param A Matrix or vector. * @return The norm. */ public static double normPInf( DenseMatrix64F A ) { if( MatrixFeatures.isVector(A)) { return CommonOps.elementMaxAbs(A); } else { return inducedPInf(A); } }
public synchronized void setMatrix( D1Matrix64F A ) { double maxValue = CommonOps.elementMaxAbs(A); renderMatrix(A,image,maxValue); repaint(); }
/** * Computes the p=1 norm. If A is a matrix then the induced norm is computed. * * @param A Matrix or vector. * @return The norm. */ public static double normP1( DenseMatrix64F A ) { if( MatrixFeatures.isVector(A)) { return CommonOps.elementSumAbs(A); } else { return inducedP1(A); } }