init
This commit is contained in:
25
Common/DTS.Common.Utilities/StandardDev.cs
Normal file
25
Common/DTS.Common.Utilities/StandardDev.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace DTS.Utilities
|
||||
{
|
||||
public class StandardDev
|
||||
{
|
||||
public static double StandardDeviation(IEnumerable<double> values)
|
||||
{
|
||||
double standardDeviation = 0;
|
||||
|
||||
if (!values.Any()) return standardDeviation;
|
||||
// Compute the average.
|
||||
double avg = values.Average();
|
||||
|
||||
// Perform the Sum of (value-avg)_2_2.
|
||||
double sum = values.Sum(d => System.Math.Pow(d - avg, 2));
|
||||
|
||||
// Put it all together.
|
||||
standardDeviation = System.Math.Sqrt((sum) / (values.Count() - 1));
|
||||
|
||||
return standardDeviation;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user