One-pass (O(N)) descriptive statistics. Statistics are always ready and O(1) to retrieve — no recalculation needed.
dotnet add package OnTheFlyStats- Mean (arithmetic, geometric, root-mean-square)
- Variance (population and sample)
- Standard deviation (population and sample)
- Standard error of the mean
- Z-score / standard score
- Sum, min, max
- Range and mid-range
- Count (N)
Instead of recalculating mean each loop iteration:
foreach (var item in populationList)
{
averageLabel.Value = populationList.Average(); // O(N²) — never do this
minLabel.Value = populationList.Min();
maxLabel.Value = populationList.Max();
}Use:
var stats = new Stats();
foreach (var item in populationList)
{
stats.Update(item);
averageLabel.Value = stats.Mean;
minLabel.Value = stats.Min;
maxLabel.Value = stats.Max;
}Or compute from a collection in one line:
var stats = matrix[x].Stats();
var listMin = stats.Min;
var listMax = stats.Max;var roc = new ReceiverOperatorCharacteristic(expected, predicted);
Console.WriteLine($"Accuracy: {roc.Accuracy:P1}");
Console.WriteLine($"Sensitivity: {roc.Sensitivity:P1}");
Console.WriteLine($"Specificity: {roc.Specificity:P1}");