EmMax
EmMax
creates an EM Max (exponential moving maximum) for an updateBy
table operation. The formula for an EM Max is:
Where:
- is the window size, an input parameter to the method.
- is the EM Max.
- is the current value.
- denotes the step. The current step is , and the previous step is .
Syntax
EmMax(tickDecay, pairs...)
EmMax(control, tickDecay, pairs...)
EmMax(control, timestampColumn, timeDecay, pairs...)
EmMax(control, timestampColumn, durationDecay, pairs...)
EmMax(timestampColumn, timeDecay, pairs...)
EmMax(timestampColumn, durationDecay, pairs...)
Parameters
Parameter | Type | Description |
---|---|---|
tickDecay | double | The decay rate in ticks (rows). |
pairs | String... | The input/output column name pairs. |
control | OperationControl | Defines how special cases should behave. If not given, default OperationControl settings are used. |
timestampColumn | String | The column in the source table to use for timestamps. |
timeDecay | long | The decay rate in nanoseconds. |
durationDecay | Duration | The decay rate in a Duration object. |
Returns
An UpdateByOperation
to be used in an updateBy
table operation.
Examples
One column, no groups
The following example calculates the tick-based and time-based EM Max of the X
column, renaming the resultant column to EmMax_X
. The tick decay rate is set to 5 rows, and the time decay rate is set to 5 seconds. No grouping columns are specified, so the EM Max is calculated for all rows.
baseTime = parseInstant("2023-01-01T00:00:00 ET")
source = emptyTable(10).update("Timestamp = baseTime + i * SECOND", "Letter = (i % 2 == 0) ? `A` : `B`", "X = randomInt(0,25)")
result = source.updateBy([EmMax(5, "EmMax_Tick_X = X"), EmMax("Timestamp", 5 * SECOND, "EmMax_Time_X = X")])
- source
- result
One EM Max column, one grouping column
The following example builds on the previous by specifying Letter
as the key column. Thus, the EM Max is calculated on a per-letter basis.
baseTime = parseInstant("2023-01-01T00:00:00 ET")
source = emptyTable(10).update("Timestamp = baseTime + i * SECOND", "Letter = (i % 2 == 0) ? `A` : `B`", "X = randomInt(0,25)")
result = source.updateBy([EmMax(5, "EmMax_Tick_X = X"), EmMax("Timestamp", 5 * SECOND, "EmMax_Time_X = X")], "Letter")
- source
- result
Multiple EM Max columns, multiple grouping columns
The following example builds on the previous by calculating the EM Max of multiple columns with each UpdateByOperation
. Also, the groups are defined by unique combinations of letter and boolean in the Letter
and Truth
columns, respectively.
baseTime = parseInstant("2023-01-01T00:00:00 ET")
source = emptyTable(20).update("Timestamp = baseTime + i * SECOND", "Letter = (i % 2 == 0) ? `A` : `B`", "Truth = randomBool()", "X = randomInt(0, 25)", "Y = randomInt(0, 25)")
result = source.updateBy([EmMax(2, "EmMax_Tick_X = X", "EmMax_Tick_Y = Y"), EmMax("Timestamp", 3 * SECOND, "EmMax_Time_X = X", "EmMax_Time_Y = Y")], "Letter", "Truth")
- source
- result
Multiple UpdateByOperations
, multiple grouping columns
The following example builds on the previous by calculating the tick- and time-based EM Max of the X and Y columns using different EM Max
UpdateByOperations. This allows each EM Max to have its own decay rate. The decay rates are reflected in the renamed resultant columns.
baseTime = parseInstant("2023-01-01T00:00:00 ET")
source = emptyTable(20).update("Timestamp = baseTime + i * SECOND", "Letter = (i % 2 == 0) ? `A` : `B`", "Truth = randomBool()", "X = randomInt(0, 25)", "Y = randomInt(0, 25)")
emmaxTickX = EmMax(1, "EmMax_Tick_X_1row = X")
emmaxTickY = EmMax(5, "EmMax_Tick_Y_5rows = Y")
emmaxTimeX = EmMax("Timestamp", 2 * SECOND, "EmMax_Time_X_2sec = X")
emmaxTimeY = EmMax("Timestamp", 4 * SECOND, "EmMax_Time_Y_4sec = Y")
result = source.updateBy([emmaxTickX, emmaxTickY, emmaxTimeX, emmaxTimeY], "Letter", "Truth")
- source
- result