如何计算的标准偏差[阵列] [英] How to calculate a standard deviation [array]

查看:239
本文介绍了如何计算的标准偏差[阵列]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.

这篇关于如何计算的标准偏差[阵列]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆