C#标准偏差 [英] C# standard deviation
问题描述
伙计们.我是c#菜鸟,但我确实需要专业的帮助.我将Visual Studio 2005用于一个项目,所以我没有math.linq,我需要计算通用对象列表的标准差.该列表仅包含浮点数列表,没有什么太复杂的.但是我以前从未做过此事,因此我需要有人告诉我之前已计算出通用列表的标准差.这是我尝试开始的代码:
Guys. Im a c# noob but I really need a professional''s help. I am using visual studio 2005 for a project so I dont have math.linq I need to calculate the standard deviation of a generic list of objects. The list contains just a list of float numbers, nothing too complicated. However I have never done this before so i need someone to show me that has calculated standard deviation of a generic list before. Here is my code that I tried to start on:
//this is my list of objects inside. The valve data just contains a bunch of floats.
public class ValveDataResults
{
private List<valvedata> m_ValveResults;
public void AddValveData(ValveData valve)
{
m_ValveResults.Add(valve);
}
//this is the function where the standard deviation needs to be calculated:
public float LatchTimeStdev()
{
//below this is a working example of how to get an average or mean
//of same list and same "LatchTime" that needs to be calculated here as well.
}
//function to calculate average of latch time, can be copied for above st dev.
public float LatchTimeMean()
{
float returnValue = 0;
foreach (ValveData value in m_ValveResults)
{
returnValue += value.LatchTime;
}
returnValue = (returnValue / m_ValveResults.Count) * 0.02f;
return returnValue;
}</valvedata>
锁定时间"是"ValveData"对象的一个浮动对象,该对象被插入到m_ValveResults列表中.
而已.任何帮助将不胜感激.谢谢
[修改:如果您添加< pre lang ="cs">在代码和</pre>之前代码后,它将为您设置格式!]
the "Latch Time" is a float object of the "ValveData" object which is inserted into the m_ValveResults list.
thats it. any help would much be appreciated. Thanks
[Modified: if you add <pre lang="cs"> before the code and </pre> after the code, it will format it for you!]
推荐答案
一个简单的Google搜索C#和标准差的方法如下:
A simple google search of c# and standard deviation gave this:
private double getStandardDeviation(List<double> doubleList)
{
double average = doubleList.Average();
double sumOfDerivation = 0;
foreach (double value in doubleList)
{
sumOfDerivation += (value) * (value);
}
double sumOfDerivationAverage = sumOfDerivation / doubleList.Count;
return Math.Sqrt(sumOfDerivationAverage - (average*average));
}
这篇关于C#标准偏差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!