double[] someDoubles = { 34.6, 45.1, 55.5, 78.5, 84.66, **1400.32**, 99.04, 103.99 };
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# Calculate a deviation? Algorithm that sort out the rows who breaks the cumulative chain?
Advices are of help,
[INSERT]
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.
Using LINQ:
double average = someDoubles.Average(); double sumOfSquaresOfDifferences = someDoubles.Select(val => (val - average) * (val - average)).Sum(); double sd = Math.Sqrt(sumOfSquaresOfDifferences / someDoubles.Length);
The sd
variable will have the standard deviation.
If you have a List<double>
, then use someDoubles.Count
in the last line for code instead of someDoubles.Length
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With