/** * <p> * Element wise p-norm:<br> * <br> * norm = {∑<sub>i=1:m</sub> ∑<sub>j=1:n</sub> { |a<sub>ij</sub>|<sup>p</sup>}}<sup>1/p</sup> * </p> * * <p> * This is not the same as the induced p-norm used on matrices, but is the same as the vector p-norm. * </p> * * @param A Matrix. Not modified. * @param p p value. * @return The norm's value. */ public static float elementP(FMatrix1Row A, float p) { if (p == 1) { return(CommonOps_FDRM.elementSumAbs(A)); } if (p == 2) { return(normF(A)); } else { float max = CommonOps_FDRM.elementMaxAbs(A); if (max == 0.0f) { return(0.0f); } float total = 0; int size = A.getNumElements(); for (int i = 0; i < size; i++) { float a = A.get(i) / max; total += (float)Math.Pow(Math.Abs(a), p); } return(max * (float)Math.Pow(total, 1.0f / p)); } }
/** * <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 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); }