Module org.elasticsearch.xcore
Class ExponentialAverageCalculationContext
java.lang.Object
org.elasticsearch.xpack.core.ml.utils.ExponentialAverageCalculationContext
- All Implemented Interfaces:
Writeable,org.elasticsearch.xcontent.ToXContent,org.elasticsearch.xcontent.ToXContentObject
public class ExponentialAverageCalculationContext
extends Object
implements Writeable, org.elasticsearch.xcontent.ToXContentObject
Utility for calculating current value of exponentially-weighted moving average per fixed-sized time window.
The formula for the current value of the exponentially-weighted moving average is:
currentExponentialAverageMs = alpha * previousExponentialAverageMs + (1 - alpha) * incrementalMetricValueMs
where alpha depends on what fraction of the current time window we've already seen:
alpha = e^(-time_elapsed_since_window_start/window_size)
time_elapsed_since_window_start = latestTimestamp - window_start
The class holds 3 values based on which it performs the calculation:
- incrementalMetricValueMs - accumulated value of the metric in the current time window
- latestTimestamp - timestamp updated as the time passes through the current time window
- previousExponentialAverageMs - exponential average for previous time windows
incrementalMetricValueMs should be updated using
increment(double).
latestTimestamp should be updated using setLatestTimestamp(java.time.Instant).
Because it can happen that the timestamp is not available while incrementing the metric value, it is the responsibility of the user
of this class to always call setLatestTimestamp(java.time.Instant) *after* all the relevant (i.e. referring to the points in time before the
latest timestamp mentioned) increment(double) calls are made.-
Nested Class Summary
Nested classes/interfaces inherited from interface org.elasticsearch.xcontent.ToXContent
org.elasticsearch.xcontent.ToXContent.DelegatingMapParams, org.elasticsearch.xcontent.ToXContent.MapParams, org.elasticsearch.xcontent.ToXContent.ParamsNested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V> -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final org.elasticsearch.xcontent.ParseFieldstatic final org.elasticsearch.xcontent.ParseFieldstatic final org.elasticsearch.xcontent.ConstructingObjectParser<ExponentialAverageCalculationContext, Void> static final org.elasticsearch.xcontent.ParseFieldFields inherited from interface org.elasticsearch.xcontent.ToXContent
EMPTY, EMPTY_PARAMS -
Constructor Summary
ConstructorsConstructorDescriptionExponentialAverageCalculationContext(double incrementalMetricValueMs, Instant latestTimestamp, Double previousExponentialAverageMs) -
Method Summary
Modifier and TypeMethodDescriptionbooleandoubleinthashCode()voidincrement(double metricValueDeltaMs) Increments the current accumulated metric value by the given delta.voidsetLatestTimestamp(Instant newLatestTimestamp) Sets the latest timestamp that serves as an indication of the current point in time.toString()org.elasticsearch.xcontent.XContentBuildertoXContent(org.elasticsearch.xcontent.XContentBuilder builder, org.elasticsearch.xcontent.ToXContent.Params params) voidwriteTo(StreamOutput out) Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.elasticsearch.xcontent.ToXContentObject
isFragment
-
Field Details
-
INCREMENTAL_METRIC_VALUE_MS
public static final org.elasticsearch.xcontent.ParseField INCREMENTAL_METRIC_VALUE_MS -
LATEST_TIMESTAMP
public static final org.elasticsearch.xcontent.ParseField LATEST_TIMESTAMP -
PREVIOUS_EXPONENTIAL_AVERAGE_MS
public static final org.elasticsearch.xcontent.ParseField PREVIOUS_EXPONENTIAL_AVERAGE_MS -
PARSER
public static final org.elasticsearch.xcontent.ConstructingObjectParser<ExponentialAverageCalculationContext,Void> PARSER
-
-
Constructor Details
-
ExponentialAverageCalculationContext
public ExponentialAverageCalculationContext() -
ExponentialAverageCalculationContext
-
ExponentialAverageCalculationContext
-
ExponentialAverageCalculationContext
- Throws:
IOException
-
-
Method Details
-
getIncrementalMetricValueMs
public double getIncrementalMetricValueMs() -
getLatestTimestamp
-
getPreviousExponentialAverageMs
-
getCurrentExponentialAverageMs
-
increment
public void increment(double metricValueDeltaMs) Increments the current accumulated metric value by the given delta. -
setLatestTimestamp
Sets the latest timestamp that serves as an indication of the current point in time. Before calling this method make sure all the associated calls toincrement(double)were already made. -
writeTo
- Specified by:
writeToin interfaceWriteable- Throws:
IOException
-
toXContent
public org.elasticsearch.xcontent.XContentBuilder toXContent(org.elasticsearch.xcontent.XContentBuilder builder, org.elasticsearch.xcontent.ToXContent.Params params) throws IOException - Specified by:
toXContentin interfaceorg.elasticsearch.xcontent.ToXContent- Throws:
IOException
-
equals
-
hashCode
public int hashCode() -
toString
-