/// <summary>
        /// Compute Standard Deviation. In case of both subMean and useStd are true, we technically need to compute variance
        /// based on centered values (i.e. after subtracting the mean). But since the centered
        /// values mean is approximately zero, we can use variance of non-centered values.
        /// </summary>
        private static Float StdDev(Float[] values, int count, int length)
        {
            Contracts.Assert(0 <= count && count <= length);
            if (count == 0)
            {
                return(0);
            }
            // We need a mean to compute variance.
            Float tmpMean = SseUtils.Sum(values, 0, count) / length;
            Float sumSq   = 0;

            if (count != length && tmpMean != 0)
            {
                // Sparse representation.
                Float meanSq = tmpMean * tmpMean;
                sumSq = (length - count) * meanSq;
            }
            sumSq += SseUtils.SumSq(tmpMean, values, 0, count);
            return(MathUtils.Sqrt(sumSq / length));
        }
示例#2
0
 public static float Sum(float[] src, int offset, int count) => SseUtils.Sum(src, offset, count);