double[] someDoubles = { 34.6, 45.1, 55.5, 78.5, 84.66, **1400.32**, 99.04, 103.99 };
这code以上是累积算法的意外行为的人手短缺的样品(参照粗值)。在真实的,这是一类其中还包含一个日期与每个值
This code above is a short-handed sample of an unexpected behavior of an cumulative algorithm (see the bold value). In real, this is a class which also holds a date with each value.
C#中计算的偏差? 算法谁打破了累积链的行之后的整理?
C# Calculate a deviation? Algorithm that sort out the rows who breaks the cumulative chain?
通知书的帮助,
[插入]
要澄清,这是三件事情 性能是这个话题非常重要的。
To clarify, this is about three things Performance is really important on this topic.
第一:快速扫描,如果值如下累积模式。 二:检查是否所有的值进入一个合理的偏差。 三:指出并做错误处理。
First: Fast-Scan if the values follows a cumulative pattern. Second: Check if all values goes into a reasonable deviation. Third: Point out and do error handling.
这个问题是关于第一和第二。
This question is about the first and second.
使用lambda表达式
Using lambdas
double average = someDoubles.Average();
double sumOfSquaresOfDifferences = someDoubles.Select(val => (val - average) * (val - average)).Sum();
double sd = Math.Sqrt(sumOfSquaresOfDifferences / someDoubles.Length);
SD 变量将有标准偏差。
sd variable will have the standard deviation.
如果你有一个名单,其中,双>
,然后用 someDoubles.Count
为$ c中的最后一行$ C,而不是 someDoubles.Length
。
If you have a List<double>
, then use someDoubles.Count
in the last line for code instead of someDoubles.Length
.