/** * <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 double elementP(DMatrix1Row A, double p) { if (p == 1) { return(CommonOps_DDRM.elementSumAbs(A)); } if (p == 2) { return(normF(A)); } else { double max = CommonOps_DDRM.elementMaxAbs(A); if (max == 0.0) { return(0.0); } double total = 0; int size = A.getNumElements(); for (int i = 0; i < size; i++) { double a = A.get(i) / max; total += Math.Pow(Math.Abs(a), p); } return(max * Math.Pow(total, 1.0 / 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_DDRM#householder(double, DMatrixD1, DMatrixD1, DMatrixD1)} 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 DMatrixRMaj createReflector(DMatrix1Row u) { if (!MatrixFeatures_DDRM.isVector(u)) { throw new ArgumentException("u must be a vector"); } double norm = NormOps_DDRM.fastNormF(u); double gamma = -2.0 / (norm * norm); DMatrixRMaj Q = CommonOps_DDRM.identity(u.getNumElements()); CommonOps_DDRM.multAddTransB(gamma, u, u, Q); return(Q); }