series_exp_smoothing_fl()
Applies a basic exponential smoothing filter on a series.
The function series_exp_smoothing_fl()
is a user-defined function (UDF) that takes an expression containing a dynamic numerical array as input and applies a basic exponential smoothing filter.
Syntax
series_exp_smoothing_fl(
y_series [,
alpha ])
Parameters
Name | Type | Required | Description |
---|---|---|---|
y_series | dynamic | ✔️ | An array cell of numeric values. |
alpha | real | A value in the range [0-1] that specifies the weight of the last point vs. the weight of the previous points, which is 1 - alpha . The default is 0.5. |
Function definition
You can define the function by either embedding its code as a query-defined function, or creating it as a stored function in your database, as follows:
Query-defined
Define the function using the following let statement. No permissions are required.
let series_exp_smoothing_fl = (y_series:dynamic, alpha:double=0.5)
{
series_iir(y_series, pack_array(alpha), pack_array(1, alpha-1))
};
// Write your query to use the function here.
Stored
Define the stored function once using the following .create function
. Database User permissions are required.
.create-or-alter function with (folder = "Packages\\Series", docstring = "Basic exponential smoothing for a series")
series_exp_smoothing_fl(y_series:dynamic, alpha:double=0.5)
{
series_iir(y_series, pack_array(alpha), pack_array(1, alpha-1))
}
Example
Query-defined
To use a query-defined function, invoke it after the embedded function definition.
let series_exp_smoothing_fl = (y_series:dynamic, alpha:double=0.5)
{
series_iir(y_series, pack_array(alpha), pack_array(1, alpha-1))
};
range x from 1 to 50 step 1
| extend y = x % 10
| summarize x = make_list(x), y = make_list(y)
| extend exp_smooth_y = series_exp_smoothing_fl(y, 0.4)
| render linechart
Stored
range x from 1 to 50 step 1
| extend y = x % 10
| summarize x = make_list(x), y = make_list(y)
| extend exp_smooth_y = series_exp_smoothing_fl(y, 0.4)
| render linechart
Output
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.