コード例 #1
0
ファイル: SparseVector.cs プロジェクト: wibble82/mmbot
        /// <summary>
        /// Computes the p-Norm.
        /// </summary>
        /// <param name="p">The p value.</param>
        /// <returns>Scalar <c>ret = (sum(abs(this[i])^p))^(1/p)</c></returns>
        public override Complex32 Norm(double p)
        {
            if (1 > p)
            {
                throw new ArgumentOutOfRangeException("p");
            }

            if (NonZerosCount == 0)
            {
                return(Complex32.Zero);
            }

            if (2.0 == p)
            {
                return(_nonZeroValues.Aggregate(Complex32.Zero, SpecialFunctions.Hypotenuse).Magnitude);
            }

            if (Double.IsPositiveInfinity(p))
            {
                return(CommonParallel.Select(0, NonZerosCount, (index, localData) => Math.Max(localData, _nonZeroValues[index].Magnitude), Common.Max));
            }

            var sum = 0.0;

            for (var index = 0; index < NonZerosCount; index++)
            {
                sum += Math.Pow(_nonZeroValues[index].Magnitude, p);
            }

            return((float)Math.Pow(sum, 1.0 / p));
        }
コード例 #2
0
ファイル: DenseVector.cs プロジェクト: waffle-iron/nequeo
        /// <summary>
        /// Computes the p-Norm.
        /// </summary>
        /// <param name="p">The p value.</param>
        /// <returns>Scalar <c>ret = (sum(abs(this[i])^p))^(1/p)</c></returns>
        public override double Norm(double p)
        {
            if (p < 0.0)
            {
                throw new ArgumentOutOfRangeException("p");
            }

            if (1.0 == p)
            {
                return(SumMagnitudes());
            }

            if (2.0 == p)
            {
                return(Data.Aggregate(0.0, SpecialFunctions.Hypotenuse));
            }

            if (Double.IsPositiveInfinity(p))
            {
                return(CommonParallel.Select(
                           0,
                           Count,
                           (index, localData) => Math.Max(localData, Math.Abs(Data[index])),
                           Math.Max));
            }

            var sum = 0.0;

            for (var index = 0; index < Count; index++)
            {
                sum += Math.Pow(Math.Abs(Data[index]), p);
            }

            return(Math.Pow(sum, 1.0 / p));
        }
コード例 #3
0
ファイル: Vector.cs プロジェクト: rherbrich/mathnet-numerics
        /// <summary>
        /// Computes the p-Norm.
        /// </summary>
        /// <param name="p">
        /// The p value.
        /// </param>
        /// <returns>
        /// <c>Scalar ret = (sum(abs(At(i))^p))^(1/p)</c>
        /// </returns>
        public override Complex32 Norm(double p)
        {
            if (p < 0.0)
            {
                throw new ArgumentOutOfRangeException("p");
            }

            if (double.IsPositiveInfinity(p))
            {
                return(CommonParallel.Select(
                           0,
                           Count,
                           (index, localData) => Math.Max(localData, At(index).Magnitude),
                           Common.Max));
            }

            var sum = 0.0;

            for (var index = 0; index < Count; index++)
            {
                sum += Math.Pow(At(index).Magnitude, p);
            }

            return((float)Math.Pow(sum, 1.0 / p));
        }
コード例 #4
0
ファイル: DenseVector.cs プロジェクト: waffle-iron/nequeo
        /// <summary>
        /// Computes the p-Norm.
        /// </summary>
        /// <param name="p">The p value.</param>
        /// <returns>Scalar <c>ret = (sum(abs(this[i])^p))^(1/p)</c></returns>
        public override Complex32 Norm(double p)
        {
            if (p < 0.0)
            {
                throw new ArgumentOutOfRangeException("p");
            }

            if (1.0 == p)
            {
                return(SumMagnitudes());
            }

            if (2.0 == p)
            {
                return(Data.Aggregate(Complex32.Zero, SpecialFunctions.Hypotenuse).Magnitude);
            }

            if (Double.IsPositiveInfinity(p))
            {
                return(CommonParallel.Select(
                           0,
                           Count,
                           (index, localData) => Math.Max(localData, Data[index].Magnitude),
                           Common.Max));
            }

            var sum = 0.0;

            for (var i = 0; i < Count; i++)
            {
                sum += Math.Pow(Data[i].Magnitude, p);
            }

            return((float)Math.Pow(sum, 1.0 / p));
        }
コード例 #5
0
ファイル: Vector.cs プロジェクト: sweetie-bot-project/sw2urdf
        /// <summary>
        /// Computes the p-Norm.
        /// </summary>
        /// <param name="p">
        /// The p value.
        /// </param>
        /// <returns>
        /// <c>Scalar ret = (sum(abs(this[i])^p))^(1/p)</c>
        /// </returns>
        public override double Norm(double p)
        {
            if (p < 0.0)
            {
                throw new ArgumentOutOfRangeException("p");
            }

            if (Double.IsPositiveInfinity(p))
            {
                return(CommonParallel.Select(
                           0,
                           Count,
                           (index, localData) => Math.Max(localData, Math.Abs(At(index))),
                           Math.Max));
            }

            var sum = 0.0;

            for (var index = 0; index < Count; index++)
            {
                sum += Math.Pow(Math.Abs(At(index)), p);
            }

            return(Math.Pow(sum, 1.0 / p));
        }
コード例 #6
0
        /// <summary>
        /// Computes the p-Norm.
        /// </summary>
        /// <param name="p">
        /// The p value.
        /// </param>
        /// <returns>
        /// <c>Scalar ret = (sum(abs(this[i])^p))^(1/p)</c>
        /// </returns>
        public override float Norm(double p)
        {
            if (p < 0.0)
            {
                throw new ArgumentOutOfRangeException("p");
            }

            if (float.IsPositiveInfinity((float)p))
            {
                return(CommonParallel.Select(
                           0,
                           Count,
                           (index, localData) => Math.Max(localData, Math.Abs(this[index])),
                           Common.Max));
            }

            var sum = CommonParallel.Aggregate(
                0,
                Count,
                index => Math.Pow(Math.Abs(this[index]), p));

            return((float)Math.Pow(sum, 1.0 / p));
        }
コード例 #7
0
        /// <summary>
        /// Computes the p-Norm.
        /// </summary>
        /// <param name="p">
        /// The p value.
        /// </param>
        /// <returns>
        /// <c>Scalar ret = (sum(abs(this[i])^p))^(1/p)</c>
        /// </returns>
        public override Complex Norm(double p)
        {
            if (p < 0.0)
            {
                throw new ArgumentOutOfRangeException("p");
            }

            if (double.IsPositiveInfinity(p))
            {
                return(CommonParallel.Select(
                           0,
                           Count,
                           (index, localData) => Math.Max(localData, this[index].Magnitude),
                           Math.Max));
            }

            var sum = CommonParallel.Aggregate(
                0,
                Count,
                index => Math.Pow(this[index].Magnitude, p));

            return(Math.Pow(sum, 1.0 / p));
        }
コード例 #8
0
        /// <summary>
        /// Computes the p-Norm.
        /// </summary>
        /// <param name="p">The p value.</param>
        /// <returns>Scalar <c>ret = (sum(abs(this[i])^p))^(1/p)</c></returns>
        public override Complex Norm(double p)
        {
            if (p < 0.0)
            {
                throw new ArgumentOutOfRangeException("p");
            }

            if (1.0 == p)
            {
                return(CommonParallel.Aggregate(
                           0,
                           Count,
                           index => Data[index].Magnitude));
            }

            if (2.0 == p)
            {
                return(Data.Aggregate(Complex.Zero, SpecialFunctions.Hypotenuse).Magnitude);
            }

            if (Double.IsPositiveInfinity(p))
            {
                return(CommonParallel.Select(
                           0,
                           Count,
                           (index, localData) => Math.Max(localData, Data[index].Magnitude),
                           Math.Max));
            }

            var sum = CommonParallel.Aggregate(
                0,
                Count,
                index => Math.Pow(Data[index].Magnitude, p));

            return(Math.Pow(sum, 1.0 / p));
        }