Package org.rapidcontext.core.data.stat
Class MovingAverage
java.lang.Object
org.rapidcontext.core.data.stat.MovingAverage
A set of approximated moving averages. The updated averages are
calculated using only the previous average (for each window) and
the new value. Three constant window sizes are used to smooth the
output average to a different degree. Calculations use double
internally, but serialize to long values multiplied by the
corresponding window size (to preserve limited precision).
- Version:
- 1.0
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionMovingAverage
(double initial) Initializes a new set of moving averages with an initial value.MovingAverage
(Array arr) Initializes a new set of moving averages from a serialized array. -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(double value) Adds a value to the moving average (for all windows).Returns an array with the averages for each of the window sizes (small to large).double
valueFor
(MovingAverage.Window window) Returns the approximate average for the specified window.values()
Returns an array with the averages for each of the window sizes (small to large).
-
Constructor Details
-
MovingAverage
public MovingAverage(double initial) Initializes a new set of moving averages with an initial value.- Parameters:
initial
- the initial value to use
-
MovingAverage
Initializes a new set of moving averages from a serialized array.- Parameters:
arr
- the serialized array of long values
-
-
Method Details
-
serialize
Returns an array with the averages for each of the window sizes (small to large). The returned averages are multiplied by each window size (to preserve some precision) and rounded to long values.- Returns:
- the serialized array of long values
-
values
Returns an array with the averages for each of the window sizes (small to large). The returned averages will be a rounded to long values.- Returns:
- an array of long values
-
valueFor
Returns the approximate average for the specified window.- Parameters:
window
- the window to fetch- Returns:
- the approximate average for the specified window
-
add
public void add(double value) Adds a value to the moving average (for all windows).- Parameters:
value
- the value to add
-