series_clean_anomalies_fl()
Cleans anomalous points in a series.
The function series_clean_anomalies_fl()
is a user-defined function (UDF) that takes a dynamic numerical array as input and another numerical array of anomalies and replaces the anomalies in the input array with interpolated value of their adjacent points.
Syntax
series_clean_anomalies_fl(
y_series,
anomalies)
Parameters
Name | Type | Required | Description |
---|---|---|---|
y_series | dynamic | ✔️ | The input array of numeric values. |
anomalies | dynamic | ✔️ | The anomalies array containing either 0 for normal points or any other value for anomalous points. |
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_clean_anomalies_fl = (y_series:dynamic, anomalies:dynamic)
{
let fnum = array_iff(series_not_equals(anomalies, 0), real(null), y_series); // replace anomalies with null values
series_fill_linear(fnum)
};
// 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 = "Replace anomalies by interpolated value", skipvalidation = "true")
series_clean_anomalies_fl(y_series:dynamic, anomalies:dynamic)
{
let fnum = array_iff(series_not_equals(anomalies, 0), real(null), y_series); // replace anomalies with null values
series_fill_linear(fnum)
}
Example
Query-defined
To use a query-defined function, invoke it after the embedded function definition.
let series_clean_anomalies_fl = (y_series:dynamic, anomalies:dynamic)
{
let fnum = array_iff(series_not_equals(anomalies, 0), real(null), y_series); // replace anomalies with null values
series_fill_linear(fnum)
}
;
let min_t = datetime(2016-08-29);
let max_t = datetime(2016-08-31);
demo_make_series1
| make-series num=count() on TimeStamp from min_t to max_t step 20m by OsVer
| extend anomalies = series_decompose_anomalies(num, 0.8)
| extend num_c = series_clean_anomalies_fl(num, anomalies)
| render anomalychart with (anomalycolumns=anomalies)
Stored
let min_t = datetime(2016-08-29);
let max_t = datetime(2016-08-31);
demo_make_series1
| make-series num=count() on TimeStamp from min_t to max_t step 20m by OsVer
| extend anomalies = series_decompose_anomalies(num, 0.8)
| extend num_c = series_clean_anomalies_fl(num, anomalies)
| render anomalychart with (anomalycolumns=anomalies)
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.