示例#1
0
 /**
  * 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 float normPInf(FMatrixRMaj A)
 {
     if (MatrixFeatures_FDRM.isVector(A))
     {
         return(CommonOps_FDRM.elementMaxAbs(A));
     }
     else
     {
         return(inducedPInf(A));
     }
 }
示例#2
0
 /**
  * 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 float fastNormP2(FMatrixRMaj A)
 {
     if (MatrixFeatures_FDRM.isVector(A))
     {
         return(fastNormF(A));
     }
     else
     {
         return(inducedP2(A));
     }
 }
示例#3
0
        /**
         * <p>
         * Creates a reflector from the provided vector and gamma.<br>
         * <br>
         * Q = I - &gamma; u u<sup>T</sup><br>
         * </p>
         *
         * <p>
         * In practice {@link VectorVectorMult_FDRM#householder(float, FMatrixD1, FMatrixD1, FMatrixD1)}  multHouseholder}
         * should be used for performance reasons since there is no need to calculate Q explicitly.
         * </p>
         *
         * @param u A vector.  Not modified.
         * @param gamma To produce a reflector gamma needs to be equal to 2/||u||.
         * @return An orthogonal reflector.
         */
        public static FMatrixRMaj createReflector(FMatrixRMaj u, float gamma)
        {
            if (!MatrixFeatures_FDRM.isVector(u))
            {
                throw new ArgumentException("u must be a vector");
            }

            FMatrixRMaj Q = CommonOps_FDRM.identity(u.getNumElements());

            CommonOps_FDRM.multAddTransB(-gamma, u, u, Q);

            return(Q);
        }
示例#4
0
        /**
         * <p>
         * Creates a reflector from the provided vector.<br>
         * <br>
         * Q = I - &gamma; u u<sup>T</sup><br>
         * &gamma; = 2/||u||<sup>2</sup>
         * </p>
         *
         * <p>
         * In practice {@link VectorVectorMult_FDRM#householder(float, FMatrixD1, FMatrixD1, FMatrixD1)}  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 FMatrixRMaj createReflector(FMatrix1Row u)
        {
            if (!MatrixFeatures_FDRM.isVector(u))
            {
                throw new ArgumentException("u must be a vector");
            }

            float norm  = NormOps_FDRM.fastNormF(u);
            float gamma = -2.0f / (norm * norm);

            FMatrixRMaj Q = CommonOps_FDRM.identity(u.getNumElements());

            CommonOps_FDRM.multAddTransB(gamma, u, u, Q);

            return(Q);
        }
示例#5
0
 /**
  * An unsafe but faster version of {@link #normP} that calls routines which are faster
  * but more prone to overflow/underflow problems.
  *
  * @param A Vector or matrix whose norm is to be computed.
  * @param p The p value of the p-norm.
  * @return The computed norm.
  */
 public static float fastNormP(FMatrixRMaj A, float p)
 {
     if (p == 1)
     {
         return(normP1(A));
     }
     else if (p == 2)
     {
         return(fastNormP2(A));
     }
     else if (float.IsInfinity(p))
     {
         return(normPInf(A));
     }
     if (MatrixFeatures_FDRM.isVector(A))
     {
         return(fastElementP(A, p));
     }
     else
     {
         throw new ArgumentException("Doesn't support induced norms yet.");
     }
 }