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