genericStateIterate#
- swordfish.function.genericStateIterate()#
This function performs calculation with count-based sliding windows iteratively.
Suppose X is specified as [X1, X2, …, Xn], column “factor” in the output table holds the calculation results, column “initial” is the initial column, window is set to “w”, and the iterate function is “func”. For the k-th record, the calculation rule is:
When w-0:
k=1: factor[0] = func(initial[0], X1[0], X2[0], … , Xn[0])
k>1: factor[k-1] = func(factor[(k-2)], X1[k-1], X2[k-1], … , Xn[k-1])
When w>0:
k <= w: factor[k-1] = initial[k-1]
k > w: factor[k-1] = func(factor[(k-1-w):k-1], X1[k-1], X2[k-1], … , Xn[k-1])
Note that when a pair is used to indicate index, the right boundary is not inclusive, i.e., the range of (k-1-w):k-1 is [k-1-w, k-1).
- Parameters:
X (Constant) – Can be column(s) from the input table, or the calculation results by applying a vector function to the column(s). You can set X to [] to leave it unspecified; or use a tuple to specify multiple columns for X.
initial (Constant) – Can be a column from the input table, or the calculation results by applying a vector function to it. It is used to fill the first to window-th records in the output table.
window (Constant) – A non-negative integer that specifies the window size (measured by the number of records).
func (Constant) –
A stateless user-defined function with one scalar as the return value. Arguments passed to func are as follows:
The first argument is a vector containing the previous window results if window>0, or the previous result if window=0.
Then followed by columns specified in X.
[Optional] Other fixed constants to be passed to func. In this case, you can fix the arguments with partial application.