RunningStatistics 3.0.0

dotnet add package RunningStatistics --version 3.0.0
                    
NuGet\Install-Package RunningStatistics -Version 3.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RunningStatistics" Version="3.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RunningStatistics" Version="3.0.0" />
                    
Directory.Packages.props
<PackageReference Include="RunningStatistics" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add RunningStatistics --version 3.0.0
                    
#r "nuget: RunningStatistics, 3.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package RunningStatistics@3.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=RunningStatistics&version=3.0.0
                    
Install as a Cake Addin
#tool nuget:?package=RunningStatistics&version=3.0.0
                    
Install as a Cake Tool

RunningStatistics

Online (single pass) algorithms for statistical measures based on the Julia package OnlineStats.jl by Josh Day. Useful for streaming and big data.

This package is available on NuGet

Supports .NET Standard 2.0

List of Statistics

Statistic Description
Mean The univariate mean
Sum The overall sum of double observations
Sum<T> The overall sum of any type that implements IAdditionOperators and IAdditiveIdentity
Variance The univariate variance
Extrema The min and max of double observations
Extrema<T> The min and max of any type that implements IComparable<T>
Moments The Mean, Variance, Skewness, and (excess) Kurtosis
EmpiricalCdf Approximate order statistics (quantiles)
CountMap<T> Counts for each unique value
Histogram A histogram with specified bin edges

List of Distributions

Distribution Description
Normal The univariate mean and variance
Beta The number of successes and failures

Common Interface

All running statistics implement the following interfaces:

public interface IRunningStatistic
{
    public long Nobs { get; }

    public void Reset();

    public IRunningStatistic CloneEmpty();

    public IRunningStatistic Clone();

    public void UnsafeMerge(IRunningStatistic other);
}

public interface IRunningStatistic<TObs> : IRunningStatistic
{
    public void Fit(TObs value);

    public void Fit(TObs value, long count);

    public void Fit(IEnumerable<TObs> values);

    public void Fit(IEnumerable<KeyValuePair<TObs, long>> keyValuePairs);

    public new IRunningStatistic<TObs> CloneEmpty();

    public new IRunningStatistic<TObs> Clone();

    public void UnsafeMerge(IRunningStatistic<TObs> other);
}

public interface IRunningStatistic<TObs, TSelf> : IRunningStatistic<TObs>
    where TSelf : IRunningStatistic<TObs, TSelf>
{
    public new TSelf CloneEmpty();

    public new TSelf Clone();

    public void Merge(TSelf other);
}

The interface is layered as three interfaces of increasing specificity. IRunningStatistic is the most generic and allows for mixed running statistics to be in a collection. IRunningStatistic<TObs> expands by adding information about the type of observations that the running statistic can fit. Finally IRunningStatistic<TObs, TSelf> adds information about the concrete type of the running statistic, and allows for precise cloning and merging.

Abstract Base Class

The abstract class RunningStatisticBase implements the IRunningStatistic<TObs, TSelf> interface and provides default implementations when possible.

Examples

See the RunningStatistics.Examples project for more examples.

Basic Usage

using RunningStatistics;

var mean1 = new Mean();
var mean2 = new Mean();
var ecdf = new EmpiricalCdf();

var rng = new Random();
for (var i = 0; i < 1000; i++)
{
    var x = rng.NextDouble();
    
    mean1.Fit(x);
    mean2.Fit(2*x);
    
    ecdf.Fit(x);
}

mean1.Merge(mean2);
var q1 = ecdf.Quantile(0.25);

Upgrading from v2 to v3

If you are inheriting from RunningStatisticBase, the biggest change should be the removal of the GetStatsString method. Now you should just override the ToString method.

Before:

protected override string GetStatsString() => $"μ={Mean}, σ²={Variance}";

After:

public override string ToString() => base.ToString() + $" | μ={Mean}, σ²={Variance}";
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.0 114 7/30/2025
2.0.1 185 1/30/2025
2.0.0 178 1/4/2025
1.1.1 297 6/6/2023
1.1.0 243 4/27/2023
1.0.2 243 4/13/2023
1.0.1 249 4/13/2023
1.0.0 257 4/12/2023
0.3.1 267 4/5/2023
0.3.0 271 4/4/2023
0.2.0 501 5/26/2022
0.1.1-alpha 267 5/13/2022
0.1.0-alpha 262 4/29/2022

- Split the interface once more to have an observation-agnostic interface. This allows for collections of running statistics that can have mixed observation types and mixed concrete types.
- Removed support for .NET 6.0 since it has reached EOL.
- Bug fixes for Extrema{T}.
- Improved test coverage.