Options
All
  • Public
  • Public/Protected
  • All
Menu

Class RollingAverage

RollingAverage

Utility to efficiently compute the rolling average and variance over a sliding window of samples

Hierarchy

  • RollingAverage

Index

Constructors

Properties

Methods

Constructors

constructor

  • constructor

    Parameters

    • length: number

      The number of samples required to saturate the sliding window

    Returns RollingAverage

Properties

averageSearch playground for average

average: number

Current average

varianceSearch playground for variance

variance: number

Current variance

Methods

addSearch playground for add

  • add(v: number): void
  • Adds a sample to the sample set

    Parameters

    • v: number

      The sample value

    Returns void

historySearch playground for history

  • history(i: number): number
  • Returns previously added values or null if outside of history or outside the sliding window domain

    Parameters

    • i: number

      Index in history. For example, pass 0 for the most recent value and 1 for the value before that

    Returns number

    Value previously recorded with add() or null if outside of range

isSaturatedSearch playground for isSaturated

  • isSaturated(): boolean
  • Returns true if enough samples have been taken to completely fill the sliding window

    Returns boolean

    true if sample-set saturated

resetSearch playground for reset

  • reset(): void
  • Resets the rolling average (equivalent to 0 samples taken so far)

    Returns void

Legend

  • Constructor
  • Property
  • Method
  • Property
  • Method
  • Inherited property
  • Inherited method
  • Static property
  • Static method