Пример #1
0
        /// <summary>
        /// Normalizes the supplied matrix so that the sum of all entries sums to 1. MODIFIES SOURCE!
        /// </summary>
        /// <returns>this</returns>
        public static Matrix <double> NormalizeToSum1(this Matrix <double> matrixWillBeModified)
        {
            var sum = matrixWillBeModified.Norm(x => x, KahanSum.Zero, (s, x) => s + x);

            if (sum.Value != 0.0)
            {
                double scale = 1.0 / sum.Value;
                matrixWillBeModified.Apply(x => scale * x);
            }
            return(matrixWillBeModified);
        }
Пример #2
0
        /// <summary>
        /// Normalizes the supplied matrix so that the sum of all entries sums to 1. MODIFIES SOURCE!
        /// </summary>
        /// <returns>this</returns>
        public static Matrix <float> NormalizeToSum1(this Matrix <float> matrixWillBeModified)
        {
            var sum = matrixWillBeModified.Norm(x => x, 0.0, (s, x) => s + (double)x);

            if (sum != 0.0)
            {
                double scale = 1.0 / sum;
                matrixWillBeModified.Apply(x => (float)(scale * x));
            }
            return(matrixWillBeModified);
        }