/** * Same as {@link #elementP} but runs faster by not mitigating overflow/underflow related problems. * * @param A Matrix. Not modified. * @param p p value. * @return The norm's value. */ public static double fastElementP( D1Matrix64F A , double p ) { if( p == 2 ) { return fastNormF(A); } else { double total = 0; int size = A.getNumElements(); for( int i = 0; i < size; i++ ) { double a = A.get(i); total += Math.pow(Math.abs(a),p); } return Math.pow(total,1.0/p); } }
/** * Same as {@link #elementP} but runs faster by not mitigating overflow/underflow related problems. * * @param A Matrix. Not modified. * @param p p value. * @return The norm's value. */ public static double fastElementP( D1Matrix64F A , double p ) { if( p == 2 ) { return fastNormF(A); } else { double total = 0; int size = A.getNumElements(); for( int i = 0; i < size; i++ ) { double a = A.get(i); total += Math.pow(Math.abs(a),p); } return Math.pow(total,1.0/p); } }
/** * Same as {@link #elementP} but runs faster by not mitigating overflow/underflow related problems. * * @param A Matrix. Not modified. * @param p p value. * @return The norm's value. */ public static double fastElementP( D1Matrix64F A , double p ) { if( p == 2 ) { return fastNormF(A); } else { double total = 0; int size = A.getNumElements(); for( int i = 0; i < size; i++ ) { double a = A.get(i); total += Math.pow(Math.abs(a),p); } return Math.pow(total,1.0/p); } }
/** * 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); } }
/** * 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); } }
/** * 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> * Creates a reflector from the provided vector.<br> * <br> * Q = I - γ u u<sup>T</sup><br> * γ = 2/||u||<sup>2</sup> * </p> * * <p> * In practice {@link org.ejml.alg.dense.mult.VectorVectorMult#householder(double, org.ejml.data.D1Matrix64F, org.ejml.data.D1Matrix64F, org.ejml.data.D1Matrix64F)} multHouseholder} * should be used for performance reasons since there is no need to calculate Q explicitly. * </p> * * @param u A vector. Not modified. * @return An orthogonal reflector. */ public static DenseMatrix64F createReflector( RowD1Matrix64F u ) { if( !MatrixFeatures.isVector(u)) throw new IllegalArgumentException("u must be a vector"); double norm = NormOps.fastNormF(u); double gamma = -2.0/(norm*norm); DenseMatrix64F Q = CommonOps.identity(u.getNumElements()); CommonOps.multAddTransB(gamma,u,u,Q); return Q; }
/** * <p> * Creates a reflector from the provided vector.<br> * <br> * Q = I - γ u u<sup>T</sup><br> * γ = 2/||u||<sup>2</sup> * </p> * * <p> * In practice {@link org.ejml.alg.dense.mult.VectorVectorMult#householder(double, org.ejml.data.D1Matrix64F, org.ejml.data.D1Matrix64F, org.ejml.data.D1Matrix64F)} multHouseholder} * should be used for performance reasons since there is no need to calculate Q explicitly. * </p> * * @param u A vector. Not modified. * @return An orthogonal reflector. */ public static DenseMatrix64F createReflector( RowD1Matrix64F u ) { if( !MatrixFeatures.isVector(u)) throw new IllegalArgumentException("u must be a vector"); double norm = NormOps.fastNormF(u); double gamma = -2.0/(norm*norm); DenseMatrix64F Q = CommonOps.identity(u.getNumElements()); CommonOps.multAddTransB(gamma,u,u,Q); return Q; }
/** * <p> * Creates a reflector from the provided vector.<br> * <br> * Q = I - γ u u<sup>T</sup><br> * γ = 2/||u||<sup>2</sup> * </p> * * <p> * In practice {@link org.ejml.alg.dense.mult.VectorVectorMult#householder(double, org.ejml.data.D1Matrix64F, org.ejml.data.D1Matrix64F, org.ejml.data.D1Matrix64F)} multHouseholder} * should be used for performance reasons since there is no need to calculate Q explicitly. * </p> * * @param u A vector. Not modified. * @return An orthogonal reflector. */ public static DenseMatrix64F createReflector( RowD1Matrix64F u ) { if( !MatrixFeatures.isVector(u)) throw new IllegalArgumentException("u must be a vector"); double norm = NormOps.fastNormF(u); double gamma = -2.0/(norm*norm); DenseMatrix64F Q = CommonOps.identity(u.getNumElements()); CommonOps.multAddTransB(gamma,u,u,Q); return Q; }