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


C# OrderedDictionary.Last方法代码示例

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


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

示例1: InitializeFromHistogram

        private void InitializeFromHistogram(OrderedDictionary<long, long> hist, double[] percentilesIn, out long[] percentilesOut)
        {
            percentilesOut = new long[percentilesIn.Length];
            Min = hist.Any() ? hist.First().Key : float.NaN;
            Max = hist.Any() ? hist.Last().Key : float.NaN;
            NumberOfDataPoints = hist.Values.Sum();

            long cumulativeCount = 0;
            double previousBinPercentile = 0;
            double currentBinPercentile = 0;

            //from http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Weighted_incremental_algorithm
            //D. H. D. West (1979). Communications of the ACM, 22, 9, 532-535: Updating Mean and Variance Estimates: An Improved Method
            long sumweight = 0;
            double mean = 0;
            double M2 = 0;
            foreach (KeyValuePair<long, long> bin in hist)
            {
                //handle mean and variance
                long x = bin.Key;
                long weight = bin.Value;
                long temp = weight + sumweight;
                double delta = x - mean;
                double R = delta * weight / temp;
                mean = mean + R;
                M2 = M2 + sumweight * delta * R;
                sumweight = temp;

                //handle percentiles
                cumulativeCount = sumweight;
                previousBinPercentile = currentBinPercentile;

                //percentile including values from this bin
                currentBinPercentile = ((double)cumulativeCount) / NumberOfDataPoints;

                //check if we have reached one of the percentiles
                if (0.05 > previousBinPercentile && 0.05 <= currentBinPercentile)
                {
                    Perc05 = bin.Key;
                }
                if (0.25 > previousBinPercentile && 0.25 <= currentBinPercentile)
                {
                    Perc25 = bin.Key;
                }
                if (0.5 > previousBinPercentile && 0.5 <= currentBinPercentile)
                {
                    Median = bin.Key;
                }
                if (0.75 > previousBinPercentile && 0.75 <= currentBinPercentile)
                {
                    Perc75 = bin.Key;
                }
                if (0.95 > previousBinPercentile && 0.95 <= currentBinPercentile)
                {
                    Perc95 = bin.Key;
                }

                //custom percentiles
                for (int percentileIndex = 0; percentileIndex < percentilesIn.Length; percentileIndex++)
                {
                    double percentile = percentilesIn[percentileIndex];
                    if (percentile > previousBinPercentile && percentile <= currentBinPercentile)
                    {
                        percentilesOut[percentileIndex] = bin.Key;
                    }
                }
            }
            Mean = (float)mean;
            if (NumberOfDataPoints > 1)
                Stdev = (float)Math.Sqrt(M2 / (NumberOfDataPoints - 1));
        }
开发者ID:abladon,项目名称:canvas,代码行数:71,代码来源:DescriptiveStats.cs


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