App Metrics Fork me on GitHub
Show / Hide Table of Contents

Class DefaultAlgorithmRReservoir

A histogram with a uniform reservoir produces quantiles which are valid for the entirely of the histogram’s lifetime.

This sampling reservoir can be used when you are interested in long-term measurements, it does not offer a sence of recency.

All samples are equally likely to be evicted when the reservoir is at full capacity.

Inheritance
System.Object
DefaultAlgorithmRReservoir
Namespace:App.Metrics.ReservoirSampling.Uniform
Assembly:cs.temp.dll.dll
Syntax
public sealed class DefaultAlgorithmRReservoir : IReservoir
Remarks

Uses Vitter's Algorithm R for reservoir sampling

Constructors

DefaultAlgorithmRReservoir()

Initializes a new instance of the DefaultAlgorithmRReservoir class.

Declaration
public DefaultAlgorithmRReservoir()

DefaultAlgorithmRReservoir(Int32)

Initializes a new instance of the DefaultAlgorithmRReservoir class.

Declaration
public DefaultAlgorithmRReservoir(int sampleSize)
Parameters
Type Name Description
System.Int32 sampleSize

The number of samples to keep in the sampling reservoir

Properties

Size

Gets the size.

Declaration
public int Size { get; }
Property Value
Type Description
System.Int32

The size.

Methods

GetSnapshot()

Declaration
public IReservoirSnapshot GetSnapshot()
Returns
Type Description
IReservoirSnapshot

GetSnapshot(Boolean)

Declaration
public IReservoirSnapshot GetSnapshot(bool resetReservoir)
Parameters
Type Name Description
System.Boolean resetReservoir
Returns
Type Description
IReservoirSnapshot

Reset()

Declaration
public void Reset()

Update(Int64)

Declaration
public void Update(long value)
Parameters
Type Name Description
System.Int64 value

Update(Int64, String)

Updates the sample set adding the specified value using Vitter's Algorithm R.

Declaration
public void Update(long value, string userValue)
Parameters
Type Name Description
System.Int64 value

The value to add to the sample set.

System.String userValue

The user value to track, which records the last, min and max user values within the sample.

Examples
-- S has items to sample, R will contain the result
ReservoirSample(S[1..n], R[1..k])
    -- fill the reservoir array
    for i = 1 to k
        R[i] := S[i]
        -- replace elements with gradually decreasing probability
    for i = k+1 to n
        j := random(1, i)   -- important: inclusive range
        if j <= k
        R[j] := S[i]
Back to top Copyright © 2017 Allan Hardy
Generated by DocFX