RunningStatistics 1.1.1

dotnet add package RunningStatistics --version 1.1.1                
NuGet\Install-Package RunningStatistics -Version 1.1.1                
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="1.1.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RunningStatistics --version 1.1.1                
#r "nuget: RunningStatistics, 1.1.1"                
#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.
// Install RunningStatistics as a Cake Addin
#addin nuget:?package=RunningStatistics&version=1.1.1

// Install RunningStatistics as a Cake Tool
#tool nuget:?package=RunningStatistics&version=1.1.1                

RunningStatistics

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

List of Statistics

Statistic Description
Mean The univariate mean
Sum The overall sum of double observations
Sum<T> The overall sum of any INumber<T> (requires .NET7 or higher)
Variance The univariate variance
Extrema The min and max observations and their counts
Moments Mean, Variance, Skewness, and (excess) Kurtosis
EmpiricalCdf Approximate order statistics (quantiles)
CountMap<T> Counts for each unique value
ProportionMap<T> Proportions 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 inherit from the following abstract class:

public abstract class AbstractRunningStatistic<TObs, TSelf> where TSelf : AbstractRunningStatistic<TObs, TSelf>
{
    private long _nobs;

    public long Nobs
    {
        get => GetNobs();
        protected set => _nobs = value;
    }

    protected virtual long GetNobs() => _nobs;

    public abstract void Fit(TObs value);

    public virtual void Fit(IEnumerable<TObs> values)
    {
        foreach (var value in values)
        {
            Fit(value);
        }
    }

    public abstract void Reset();

    public abstract TSelf CloneEmpty();

    public abstract TSelf Clone();

    public abstract void Merge(TSelf other);

    public static TSelf Merge(TSelf sourceStatistic, params TSelf[] stats)
    {
        var newStat = sourceStatistic.Clone();
        
        foreach (var stat in stats)
        {
            newStat.Merge(stat);
        }

        return newStat;
    }
}

Examples

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);

Combining Statistics

Different statistics are intended to be used on their own. If a collection of statistics is appropriate, then we recommend that you write your own class that inherits from AbstractRunningStatistic<TObs, YourClass> and use the desired statistics as private members. Example:

public class MyClass : AbstractRunningStatistic<double, MyClass>
{
    private EmpiricalCdf Ecdf { get; init; } = new();
    
    private CountMap<double> CountMap { get; init; } = new();


    protected override long GetNobs() => _ecdf.Nobs; 

    public override void Fit(double value)
    {
        Ecdf.Fit(value);
        CountMap.Fit(value);
    }

    public override void Reset()
    {
        Ecdf.Reset();
        CountMap.Reset();
    }

    public override MyClass CloneEmpty() => return new();

    public override MyClass Clone()
    {
        return new MyClass
        {
            Ecdf = Ecdf.Clone(),
            CountMap = CountMap.Clone()
        };
    }

    public override void Merge(MyClass other)
    {
        Ecdf.Merge(other.Ecdf);
        CountMap.Merge(other.CountMap);
    }
}

Notice that in this class, the number of observations is retrieved from _ecdf.Nobs by overriding GetNobs, and therefore Nobs never needs to be updated in the Fit method.

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 is compatible.  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 was computed.  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. 
.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 was computed. 
.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.
  • .NETStandard 2.0

    • No dependencies.
  • net7.0

    • No dependencies.

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
1.1.1 225 6/6/2023
1.1.0 190 4/27/2023
1.0.2 189 4/13/2023
1.0.1 195 4/13/2023
1.0.0 200 4/12/2023
0.3.1 212 4/5/2023
0.3.0 215 4/4/2023
0.2.0 429 5/26/2022
0.1.1-alpha 194 5/13/2022
0.1.0-alpha 175 4/29/2022