hanaml.DTW.Rdhanaml.DTW is a R wrapper
for SAP HANA PAL DTW.
hanaml.DTW( query.data, ref.data, radius = NULL, distance.level = NULL, minkowski.power = NULL, alignment.method = NULL, step.pattern = NULL, save.alignment = NULL, thread.ratio = NULL )
| query.data |
|
|---|---|
| ref.data |
|
| radius |
|
| distance.level |
Defaults to "euclidean". |
| minkowski.power |
|
| alignment.method |
Defaults to "closed". |
| save.alignment |
|
| thread.ratio |
|
| step.parttern |
|
Returns a list of DataFrames.
DataFrame Result for DTW, structured as follows:
QUERY_<ID column of query data> : ID of time-series for query.
REF_<ID column of refernece data> : ID of time-series for reference.
DISTANCE: DTW distance of the two time-series
WEIGHT: Total weight of match
AVG_DISTANCE: Normalized distance of two-series.
DataFrame Alignment(optimal match) between input time-series, structured as:
QUERY_<ID column of query data> : ID of time-series for query
REF_<ID column of reference data> : ID of time-series for reference.
QUERY_INDEX : Corresponding to index(timestamp) of query data.
REF_INDEX : Corresponding to index(timestamp) of reference data.
DataFrame Statistics for time series, structured as follows:
STAT_NAME : Statistics name
STAT_VALUE : Statistics value
Dynamic Time Warping is a method for measuring similarity between two
time series, which may vary in their speed, it makes one series match the other one
as much as possible by stretching or compressing one or both series.
It can be used for pattern matching and anomaly detection.
Input DataFrame:
> query.data$Collect() ID TIMESTAMP ATTR1 ATTR2 1 1 1 1 5.2 2 1 2 2 5.1 3 1 3 3 2.0 4 1 4 4 0.3 5 1 5 5 1.2 6 1 6 6 7.7 7 1 7 7 0.0 8 1 8 8 1.1 9 1 9 9 3.2 10 1 10 10 2.3 11 2 1 7 2.0 12 2 2 6 1.4 13 2 3 1 0.9 14 2 4 3 1.2 15 2 5 2 10.2 16 2 6 5 2.3 17 2 7 4 4.5 18 2 8 3 4.6 19 2 9 3 3.5 > ref.data$Collect() ID TIMESTAMP ATTR1 ATTR2 1 3 1 10 1.0 2 3 2 5 2.0 3 3 3 2 3.0 4 3 4 8 1.4 5 3 5 1 10.8 6 3 6 5 7.7 7 3 7 5 6.3 8 3 8 12 2.4 9 3 9 20 9.4 10 3 10 4 0.5 11 3 11 6 2.2
Call the function:
> output <- hanaml.DTW(query.data,
ref.data,
radius = -1,
thread.ratio = 1,
distance.level = "euclidean",
step.pattern = list(c(1,1,1,1,0,1),
c(1,1,1),
c(1,1,0.5,0,1,0.5)),
alignment.method = "closed",
save.alignment = TRUE)
Results:
> output[["alignment"]]$Collect() QUERY_ID REF_ID QUERY_INDEX REF_INDEX 1 1 3 0 0 2 1 3 1 1 3 1 3 2 2 4 1 3 3 2 5 1 3 4 3 6 1 3 5 4 7 1 3 5 5 8 1 3 6 6 9 1 3 6 7 10 1 3 7 8 11 1 3 7 9 12 1 3 8 10 13 1 3 9 10 14 2 3 0 0 15 2 3 1 1 16 2 3 2 2 17 2 3 3 3 18 2 3 4 4 19 2 3 4 5 20 2 3 5 6 21 2 3 6 6 22 2 3 7 7 23 2 3 7 8 24 2 3 8 9 25 2 3 8 10