2017-09-26 13 views
0

SAX를 사용하여 여러 개의 시계열을 표현하려고합니다. 그래서 유사점을 찾을 수 있습니다. R에서 jmotif 패키지를 사용하고 있습니다.jmotif 패키지를 사용하는 R의 SAX 시계열 표현

#Create an example dataframe 
example1 <- data.frame(flow=c(1.1,2.2,3.3,4.4,5.5,6.6), 
        weight1=c(7.1,7.2,7.3,7.4,7.5,7.6), 
        weight2=c(8.1,8.2,8.3,8.4,8.5,8.6)) 
# Create a timeseries object 
examplets1 <- ts(example1, start = 1, end = 6) 

#Analysis 
library(jmotif) 
#Normalise the data using Znorm 
examplezn <- znorm(examplets1, threshold = 0.01) 
#Perform piecewise aggregate approximation 
examplepaa <- paa(examplezn, 3) 
#Represent time series as SAX 
sax_via_window(examplepaa, 3, 3, 10, "mindist", 0.1) 

#This produces the result 
> sax_via_window(examplepaa, 3, 3, 10, "mindist", 0.1) 
$`0` 
[1] "bgh" 

이러한 결과를 해석하는 데 문제가 있습니다. 내가 기대할 수있는 것은 상징적 인 표현으로 각 열과 연결할 수 있습니다. 흐름 : acc, weight1 : bgh 등등. 실제 datset에는 약 100 컬럼의 ts 데이터가 있습니다!

잘못 입력 했습니까?

는 어떤 도움을 크게 여기서 문제는 내가하지 "벡터화"jmotif했다는 것을, 그래서

답변

0

을 감사합니다, 즉, 데이터가 아닌 프레임에 입력 시계열을 나타내는 숫자의 정렬 순서에만 적용의 ​​기능, 객체 또는 timeseries 객체. 확실한,하지만 난 그냥 간단하게 유지 싶었어요.

나는이 작업을 수행하는 코드를 약간 수정 않았다

, 그것은 희망 도움 :

library(jmotif) 

# create an example dataframe, list works the best cause library is not "vectorized" 
example1 <- list(flow = c(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9), 
      weight1 = c(7.1, 7.2, 7.3, 7.4, 7.5, 7.6, 7.7, 8.8, 9.9), 
      weight2 = c(8.1, 8.2, 8.3, 8.4, 8.5, 8.6, 8.7, 8.8, 8.9)) 

# this library makes working with not-vectorized code easier 
library(plyr) 

# z-normalize 
examplezn <- llply(example1, function(x){znorm(x, threshold = 0.01)}) 

# perform piecewise aggregate approximation, probably not needed for following up with SAX transform, so just for illustration ... 
llply(examplezn, function(x){paa(x, 3)}) 

# represent time series as SAX strings using via window SAX transform 
example_sax <- llply(example1, function(x){sax_via_window(x, 3, 2, 3, "none", 0.1)}) 

# convert the result to a data frame, by rows though 
df_by_row <- ldply(example_sax, unlist) 

# and finally obtain a column-oriented data frame 
df_by_column <- as.data.frame(t(df_by_row))