时间序列与表示之间的距离(逐段聚合近似-PAA)(R)

时间:2018-09-06 17:49:51

标签: r time-series distance

我试图提出一种测量时间序列与其表示形式之间的距离的方法,以查看表示形式对原始序列的接近程度。我觉得有一个简单的方法可以做到,但我无法弄清楚。下面的代码生成的图形将在每个窗口的平均值上显示红线。它是这条线与我要计算的那个窗口中每个点之间的距离。

预先感谢

################################################################################
install.packages("fitdistrplus")
install.packages("seewave")
install.packages("jmotif")
install.packages("TSdist")


library(fitdistrplus)
library(seewave)
library(jmotif)
library(TSdist)

#####################################

# set size of the SAX alphabet 
alphabet_size <- 5

# set number of elements of the PAA (Number of windows)
PAA_number <- 10

#Generate data
 x <- rlnorm(100)
 time <- seq(1,100)

#SAX (seewave) ###
  # SAX - breakpoints = sample quantiles
  sax_2 <- SAX(x,  alphabet=alphabet_size, PAA=PAA_number, breakpoints="quantiles")

  ras <- 1/alphabet_size

  #PAA lenghts for graph
  y_paa <- paa(x, PAA_number)
  x_paa <- seq(time[1], time[length(time)], length.out=PAA_number+1)


  ### 8. Plot SAX (jmotif) / sample quantiles ###
  sample_bp <- quantile(x, probs = seq(ras, 1-ras, ras))
  title2 <- "SAX sample quantiles)"
  dev.new()
  plot(time, x, type="l", col="blue", ylab="", main=title2)
  segments(x_paa[-length(x_paa)], y_paa, x_paa[-1], y_paa, col="red", lwd=2)
  abline(h=sample_bp, col="green", lty=2)
  text(x_paa[-length(x_paa)]+(x_paa[2]-x_paa[1])/2, y_paa, sax_2, pos=3, cex=0.7)
  #dev.print(pdf, paste(x_name, "SAX sample.pdf"))

0 个答案:

没有答案