当前位置: 首页>>代码示例>>C#>>正文


C# this.Average方法代码示例

本文整理汇总了C#中this.Average方法的典型用法代码示例。如果您正苦于以下问题:C# this.Average方法的具体用法?C# this.Average怎么用?C# this.Average使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在this的用法示例。


在下文中一共展示了this.Average方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Mean

        public static ICartesianCoordinate Mean(this IEnumerable<ICartesianCoordinate> pointcloud)
        {
            var X = pointcloud.Average(p => p.X);
            var Y = pointcloud.Average(p => p.Y);

            return new Point(X, Y);
        }
开发者ID:r-bel,项目名称:TSPClustering.Test,代码行数:7,代码来源:Diverse.cs

示例2: AsSextantBoundingBox

        /// <summary>
        /// Return a Rect structure indicating the bounding rectangle for the vertex
        /// from the specified tuple and the next tuple.
        /// </summary>
        public static Rect AsSextantBoundingBox(this List<Tuple<double, double>> verticies, int startingPoint)
        {
            var centerX = verticies.Average(v => v.Item1);
            var centerY = verticies.Average(v => v.Item2);

            var point1X = verticies[startingPoint].Item1;
            var point1Y = verticies[startingPoint].Item2;
            var point2X = startingPoint == 5 ? verticies[0].Item1 : verticies[startingPoint + 1].Item1;
            var point2Y = startingPoint == 5 ? verticies[0].Item2 : verticies[startingPoint + 1].Item2;

            return new Rect(Math.Min(centerX, Math.Min(point1X, point2X)),
                Math.Min(centerY, Math.Min(point1Y, point2Y)),
                (Math.Max(centerX, Math.Max(point1X, point2X)) - Math.Min(centerX, Math.Min(point1X, point2X))),
                (Math.Max(centerY, Math.Max(point1Y, point2Y)) - Math.Min(centerY, Math.Min(point1Y, point2Y))));
        }
开发者ID:JamesTStanley,项目名称:Hex,代码行数:19,代码来源:ExtensionMethods.cs

示例3: AsSextant

        /// <summary>
        /// Return a point collection of the specified point in the List of Tuples
        /// and the next point and the derived center point, for a single sextant of the hexagon
        /// </summary>
        public static PointCollection AsSextant(this List<Tuple<double, double>> verticies, int startingPoint)
        {
            var pointCollection = new PointCollection(3);

            var centerX = verticies.Average(v => v.Item1);
            var centerY = verticies.Average(v => v.Item2);

            var vertex1 = verticies[startingPoint];
            var vertex2 = startingPoint == 5 ? verticies[0] : verticies[startingPoint + 1];

            pointCollection.Add(new Point(centerX, centerY));
            pointCollection.Add(vertex1.AsPoint());
            pointCollection.Add(vertex2.AsPoint());

            return pointCollection;
        }
开发者ID:JamesTStanley,项目名称:Hex,代码行数:20,代码来源:ExtensionMethods.cs

示例4: Variance

 public static float Variance(this IEnumerable<float> source)
 {
     float avg = source.Average();
     float d = source.Aggregate(0.0f,
                                (total, next) => total + (float) Math.Pow(next - avg, 2));
     return d/(source.Count() - 1);
 }
开发者ID:idaohang,项目名称:Helicopter-Autopilot-Simulator,代码行数:7,代码来源:LinqExtensions.cs

示例5: StdDev

        public static double StdDev(this double[] data)
        {
            double avg = data.Average();

            double sum = data.Sum(x => Math.Pow(x - avg, 2));

            return Math.Sqrt(sum / data.Length);
        }
开发者ID:charvey,项目名称:facebook-mti,代码行数:8,代码来源:Extensions.cs

示例6: Average

 /// <summary>
 /// Computes the average of a sequence of TimeSpan objects
 /// </summary>
 /// <param name="spans">A sequence of values to calculate the average of</param>
 /// <returns>The average of the sequence of values</returns>
 public static TimeSpan Average(this IEnumerable<TimeSpan> Spans)
 {
     double ticks = 0;
     Spans.Check(Enumerable.Empty<TimeSpan>());
     if (Spans.Any())
         ticks = Spans.Average(a => a.Ticks);
     return new TimeSpan((long)ticks);
 }
开发者ID:kaytie,项目名称:Craig-s-Utility-Library,代码行数:13,代码来源:TimeSpanExtensions.cs

示例7: StdevS

        /// <summary>
        /// Standard dev of population sqrt(sum((item-mean)^2) / (N-1))
        /// </summary>
        public static double StdevS(this IEnumerable<double> items)
        {
            double count = items.Count();
              if (count < 2) throw new ArgumentException("StdevP called with < 2 items", "StdevP");

              double mean = items.Average();
              double sum = items.Sum<double>(d => (d - mean) * (d - mean));
              return Math.Sqrt(sum / (count - 1));
        }
开发者ID:jschlitz,项目名称:MonteCarlo,代码行数:12,代码来源:MathEx.cs

示例8: GetStdDev

        public static double GetStdDev(this float[] source)
        {
            if (source.Length <= 0)
                return 0;

            var avg = source.Average();
            var sum = source.Sum(d => Math.Pow(d - avg, 2));
            return Math.Sqrt(sum / (source.Length - 1));
        }
开发者ID:evest,项目名称:Netling,代码行数:9,代码来源:DoubleExtensions.cs

示例9: Deviations

        private static IEnumerable<Tuple<double, double>> Deviations(this ICollection<double> values)
        {
            if (values.Count == 0)
                yield break;

            var avg = values.Average();
            foreach (var d in values)
                yield return Tuple.Create(d, avg - d);
        }
开发者ID:nabuk,项目名称:NSlice,代码行数:9,代码来源:Performance.cs

示例10: StdDev

        public static double StdDev(this int[] values)
        {
            var mean = values.Average();

            var variance = values
                .Select(x => Math.Pow(mean - x, 2))
                .Average();

            return Math.Sqrt(variance);
        }
开发者ID:kornelijepetak,项目名称:incident-cs,代码行数:10,代码来源:MathExt.cs

示例11: StandardDeviation

        /// <summary>
        /// Computes the standard deviation of the given values.
        /// </summary>
        public static float StandardDeviation(this List<float> values)
        {
            if (values.Count == 0)
                return 0;

            float avg = values.Average();
            // Calculates sum((xi - avg)²)
            float sum = values.ConvertAll(val => (float)Math.Pow(val - avg, 2)).Sum();
            return (float)Math.Sqrt(sum / values.Count);
        }
开发者ID:Scriptopathe,项目名称:project-sopra,代码行数:13,代码来源:ListStatisticsExtension.cs

示例12: StandardDeviation

 public static double StandardDeviation(this IEnumerable<float> val)
 {
     double sumOfSqrs = 0;
     double avg = val.Average();
     foreach (var item in val)
     {
         sumOfSqrs += Math.Pow(((double)item - avg), 2);
     }
     double n = (double)val.Count();
     return Math.Sqrt(sumOfSqrs / (n - 1));
 }
开发者ID:sinaaslani,项目名称:kids.bmi.ir,代码行数:11,代码来源:Statistics.cs

示例13: RunningVarianceDecremental

        /// <summary>
        /// Calculates decremental running average and variance.
        /// </summary>
        /// <param name="samples">Sample data.</param>
        /// <param name="onCalculated">
        /// Action callback which fires on each element removal. 
        /// <para>Parameters are: (index, decremental average, decremental variance).</para>
        /// </param>
        /// <param name="weights">Sample weights.</param>
        public static void RunningVarianceDecremental(this IList<double> samples, Action<int, double, double> onCalculated, IList<double> weights)
        {
            double sumWeight = weights.Sum(), 
                   mean = samples.Average(weights), 
                   M2 = samples.Variance(weights) * sumWeight;

            for (int i = 0; i < samples.Count; i++)
            {
                var variance = UpdateVarianceDecremental(ref M2, ref sumWeight, ref mean, samples[i], weights[i]);
                onCalculated(i, mean, variance);
            }
        }
开发者ID:Candy29,项目名称:accord-net-extensions,代码行数:21,代码来源:RunningWeightedVariance.cs

示例14: RunningAverageDecremental

        /// <summary>
        /// Calculates decremental running average.
        /// </summary>
        /// <param name="data">Sample data.</param>
        /// <param name="onCalculated">
        /// Action callback which fires on each element removal. 
        /// <para>Parameters are: (index, decremental average).</para>
        /// </param>
        public static void RunningAverageDecremental(this IList<double> data, Action<int, double> onCalculated)
        {
            var avg = data.Average();

            for (int i = 0; i < data.Count; i++)
            {
                var item = data[i];

                avg -= UpdateAverageDecremental(avg, data.Count - i, item);
                onCalculated(i, avg);
            }
        }
开发者ID:remingtonsteel,项目名称:accord-net-extensions,代码行数:20,代码来源:RunningAverage.cs

示例15: StandardDeviation

 public static decimal StandardDeviation(this IEnumerable<decimal> values)
 {
     Contract.Requires(values != null);
     decimal ret = 0;
     var count = values.Count();
     if (count > 1)
     {
         var avg = values.Average();
         var sum = values.Sum(d => (d - avg) * (d - avg));
         ret = (decimal) Math.Sqrt((double) (sum / count));
     }
     return ret;
 }
开发者ID:kuritka,项目名称:CommodityQuotations,代码行数:13,代码来源:StatisticsEextension.cs


注:本文中的this.Average方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。