public static double StandardDeviation(IEnumerable‹double› sequence)
{
var computation = (Count: 0, Sum: 0.0, SumOfSquares: 0.0);
foreach (var item in sequence)
{
computation.Count++;
computation.Sum += item;
computation.SumOfSquares += item * item;
}
var variance = computation.SumOfSquares - computation.Sum * computation.Sum / computation.Count;
return Math.Sqrt(variance / computation.Count);
}