Reduction Behaviors
The following reduction behaviors can be used:
- Accumulate_Rolling
- Accumulate_Rolling(input, windowStart)
- Window_Signal
- Window_Signal(input, limit)
- Accumulate_Prefix
- Accumulate_Reset
- Accumulate_Samples
Calculates the reduction over a moving window.
Syntax:
- result = Accumulate_Rolling_<reduction function>(input, range)
Arguments:
- T result: the reduction function applied to the given range
- T input: the signal to be reduced
- double range: a sequence of ranges
Note: T can be any type supported by the given reduction function.
Accumulate_Rolling(input, windowStart)
The Accumulate_Rolling behavior applies the reduction function to a moving window. The windowStart signal specifies a window (see Ranges). For each range, the samples in that range from the input signal are reduced according to the reduction function and produce an output sample which has the same time stamp as the end of the range.
Examples:
-
Rolling average over the last 2 seconds:
Accumulate_Rolling_Average(input, Master()-2)
-
Rolling average over the last 10 samples:
Accumulate_Rolling_Average(input, State_Delay(Master(), 0, 10))
Notes:
- The memory usage of accumulate rolling behavior grows with the number of samples in the window. It is possible to use windowStart = 0, however each new sample will increase the memory. Depending on the input signal, this may lead to using significant amounts of memory.
-
For correct functionality, the start times of the ranges must be monotonously increasing.
Calculates a window with a given "size".
Syntax:
- Window_Signal_<reduction function>(input, limit)
Arguments:
- double result: ranges of input that have the given size of limit
- T input: the input signal that is reduced to determine the size of a window
- T limit: desired "size" of the calculated ranges
Note: T can be any type supported by the given reduction function.
The Window_Signal behavior calculates for each input sample a range ending at that sample. The size and thus the start of the range is chosen such that when applying the reduction function to the values of the input in this range the reduction approximately equals the limit. More specific the smallest interval is chosen where the reduction is greater or equal the limit.
As an example, we can apply the Accumulate_Rolling to the result to see the actual accumulated values for the window.
result = Accumulate_Rolling_<function>(input, Window_Signal_<function>(input, limit))
The result will be greater or equal the limit except at the start of the signal when there are not yet enough samples.
Example:
-
Creating a moving window always containing at least 80 grams of CO2 exhaust:
movingWindow = Window_Signal_Integral(CO2, 80)
The movingWindow can now be used to evaluate other signals normalized to the CO2 exhaust.
Calculates the reduction of a given signal from start to current sample.
Syntax:
- result = Accumulate_Prefix_<reduction_function>(input)
Arguments:
- T result: the reduction of signal from start to current sample
- T input : the signal to be reduced
Note: T can be any type supported by the given reduction function.
The Accumulate_Prefix reduction behavior accumulates the input samples with the given reduction function. The result is a signal with all the intermediate results, i.e. result[i] = reduce(signal[1], …, signal[i]).
Note: result = Accumulate_Rolling(signal, -Infinity) except that the memory usage is constant.
Calculates the reduction of a given signal from the last reset to the current sample.
Syntax:
- result = Accumulate_Reset_<reduction_function>(input, reset)
Arguments:
- T result: the reduction over signal since the last reset
- T input: the signal to be reduced
- bool reset: reduction is restarted when true
Note: T can be any type supported by the given reduction function.
The Accumulate_Reset reduction behavior accumulates the input samples with the given reduction function. The reduction is restarted when the reset input is true. The result is a signal with all the intermediate results, i.e. result[i] = reduce(signal[k], …, signal[i]) where k is the index of the last time reset was true or 1 if it never was true.
Example: Accumulate_Reset_Maximum
|
Signal |
Reset |
Result |
|---|---|---|
|
1 |
false |
1 |
|
5 |
false |
5 |
|
3 |
false |
5 |
|
2 |
true |
2 |
Calculates a rolling reduction over a given number of samples.
Syntax:
- result = Accumulate_Samples_<reduction_function>(input, count)
Arguments:
-
T result: the reduction over the last count samples
-
T input: the signal to reduce
-
const int count: the number of samples to reduce
Note: T can be any type supported by the given reduction function.
The Accumulate_Samples function calculates the reduction over the last count samples before and including the current sample. At the beginning when there are less than count samples, all available samples are reduced.
Note: Accumulate_RollingSample<R>(input, count) = Accumulate_Rolling<R>(input, State_Delay(Master(), -Infinity, count))