SlidingPercentile


@UnstableApi
public class SlidingPercentile


Calculate any percentile over a sliding window of weighted values. A maximum weight is configured. Once the total weight of the values reaches the maximum weight, the oldest value is reduced in weight until it reaches zero and is removed. This maintains a constant total weight, equal to the maximum allowed, at the steady state.

This class can be used for bandwidth estimation based on a sliding window of past transfer rate observations. This is an alternative to sliding mean and exponential averaging which suffer from susceptibility to outliers and slow adaptation to step functions.

See the following Wikipedia articles:

Summary

Public constructors

SlidingPercentile(int maxWeight)

Public methods

void
addSample(int weight, float value)

Adds a new weighted value.

float
getPercentile(float percentile)

Computes a percentile by integration.

void

Resets the sliding percentile.

Public constructors

SlidingPercentile

public SlidingPercentile(int maxWeight)
Parameters
int maxWeight

The maximum weight.

Public methods

addSample

public void addSample(int weight, float value)

Adds a new weighted value.

Parameters
int weight

The weight of the new observation.

float value

The value of the new observation.

getPercentile

public float getPercentile(float percentile)

Computes a percentile by integration.

Parameters
float percentile

The desired percentile, expressed as a fraction in the range (0,1].

Returns
float

The requested percentile value or NaN if no samples have been added.

reset

public void reset()

Resets the sliding percentile.