Skip to content

Commit

Permalink
RC Finished
Browse files Browse the repository at this point in the history
  • Loading branch information
franzbischoff committed Jun 3, 2019
1 parent 1605900 commit 5e7e30b
Show file tree
Hide file tree
Showing 91 changed files with 1,684 additions and 236 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
^cran-comments\.md$
^packrat/
^docs/
^dev/
^\.Rprofile$
^\.travis\.yml$
^.*\.Rproj$
Expand Down
7 changes: 4 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: tsmp
Type: Package
Title: Time Series with Matrix Profile
Version: 0.3.5.9001
Version: 0.3.5.9000
Authors@R: c(
person("Francisco", "Bischoff", email = "fbischoff@med.up.pt", role = c("aut", "cre"),
comment = c(ORCID = "https://orcid.org/0000-0002-5301-8672")),
Expand Down Expand Up @@ -29,11 +29,12 @@ LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 6.1.1.9000
NeedsCompilation: no
Suggests:
Suggests:
spelling,
testthat,
knitr,
rmarkdown,
gdtools,
vdiffr
vdiffr,
animation
VignetteBuilder: knitr
12 changes: 12 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Generated by roxygen2: do not edit by hand

S3method("[",AnnotationVector)
S3method("[",ArcCount)
S3method("[",Chain)
S3method("[",Discord)
S3method("[",Floss)
S3method("[",Fluss)
S3method("[",MatrixProfile)
S3method("[",Motif)
S3method("[",MultiMatrixProfile)
S3method("[",MultiMotif)
S3method("[",Salient)
S3method("[",SimpleMatrixProfile)
S3method(find_discord,MatrixProfile)
S3method(find_motif,MatrixProfile)
S3method(find_motif,MultiMatrixProfile)
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
NEWS
================
Francisco Bischoff
\- 01 Jun 2019
\- 03 Jun 2019

<!-- NEWS.md is generated from NEWS.Rmd. Please edit that file -->

Expand Down
6 changes: 4 additions & 2 deletions R/dist_profile.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@
#' # weighted
#' weight <- c(rep(1, w / 3), rep(0.5, w / 3), rep(0.8, w / 3)) # just an example
#'
#' nn <- dist_profile(ref_data, ref_data, window_size = w, index = 1, method = "weighted", weight = weight)
#' nn <- dist_profile(ref_data, ref_data, window_size = w, index = 1, method = "weighted",
#' weight = weight)
#' distance_profile <- Re(sqrt(nn$distance_profile))
dist_profile <- function(data, query, ..., window_size = NULL, method = "v3", index = 1, k = NULL, weight = NULL, paa = 1) {
dist_profile <- function(data, query, ..., window_size = NULL, method = "v3", index = 1, k = NULL,
weight = NULL, paa = 1) {

## ---- Verify if method exists ----
# set as v3 if no method is entered
Expand Down
10 changes: 5 additions & 5 deletions R/fluss.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ floss <- function(.mp, new_data, data_window, threshold = 1, exclusion_zone = NU
.mp$cac_final <- NULL
return(.mp)
} else {
.mp <- stompi_update(.mp, head(new_data, data_window - data_size))
.mp <- stompi_update(.mp, utils::head(new_data, data_window - data_size))
new_data <- new_data[(data_window - data_size + 1):new_data_size]
}
}
Expand All @@ -103,7 +103,7 @@ floss <- function(.mp, new_data, data_window, threshold = 1, exclusion_zone = NU

.mp$cac_final <- c(
rep(NA, chunk_size + mp_offset - chunk_size),
head(.mp$cac, -(round(data_window * (1 - vars()$kmode) - (1 - vars()$kmode) * .mp$w) - 0.5 * chunk_size + ifelse(mp_offset > 0, 1, 2)))
utils::head(.mp$cac, -(round(data_window * (1 - vars()$kmode) - (1 - vars()$kmode) * .mp$w) - 0.5 * chunk_size + ifelse(mp_offset > 0, 1, 2)))
)

na_head <- round(vars()$kmode * data_window + (0.5 * chunk_size - vars()$kmode * .mp$w)) + mp_offset
Expand All @@ -130,7 +130,7 @@ floss <- function(.mp, new_data, data_window, threshold = 1, exclusion_zone = NU
res <- floss_extract(.mp, threshold)

if (!keep_cac) {
res$cac_final <- tail(res$cac_final, -length(new_data))
res$cac_final <- utils::tail(res$cac_final, -length(new_data))
}

return(res)
Expand Down Expand Up @@ -179,9 +179,9 @@ floss_extract <- function(.mpac, threshold = 1, exclusion_zone = NULL) {
new_data <- ifelse(is.null(attr(.mpac, "new_data")), 0, attr(.mpac, "new_data"))

if (offset == 0 || cac_fin_len == floor((mp_len * vars()$kmode + new_data * 1.5))) {
cac <- tail(.mpac$cac_final, -new_data)
cac <- utils::tail(.mpac$cac_final, -new_data)
} else {
cac <- tail(.mpac$cac_final, -offset)
cac <- utils::tail(.mpac$cac_final, -offset)
}

cac[cac > threshold] <- NA
Expand Down
3 changes: 2 additions & 1 deletion R/mass-pre-w.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
#' w <- mp_toy_data$sub_len
#' ref_data <- mp_toy_data$data[, 1]
#' query_data <- mp_toy_data$data[, 1]
#' weight <- c(rep(1, mp_toy_data$sub_len / 3), rep(0.5, mp_toy_data$sub_len / 3), rep(1, mp_toy_data$sub_len / 3))
#' weight <- c(rep(1, mp_toy_data$sub_len / 3), rep(0.5, mp_toy_data$sub_len / 3),
#' rep(1, mp_toy_data$sub_len / 3))
#'
#' pre <- tsmp:::mass_pre_w(ref_data, query_data, w, weight)
#'
Expand Down
6 changes: 4 additions & 2 deletions R/mass.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
#' @references Website: <https://www.cs.unm.edu/~mueen/FastestSimilaritySearch.html>

#' @name mass-deprecated
#' @usage mass(data_fft, query_window, data_size, window_size, data_mean, data_sd, query_mean, query_sd)
#' @usage mass(data_fft, query_window, data_size, window_size, data_mean, data_sd,
#' query_mean, query_sd)
#' @seealso \code{\link{tsmp-deprecated}}
#' @keywords internal
NULL
Expand All @@ -33,7 +34,8 @@ NULL
#'
#' @export

mass <- function(data_fft, query_window, data_size, window_size, data_mean, data_sd, query_mean, query_sd) {
mass <- function(data_fft, query_window, data_size, window_size, data_mean, data_sd,
query_mean, query_sd) {
.Deprecated("dist_profile")
# pre-process query for fft
query_window <- rev(query_window)
Expand Down
6 changes: 4 additions & 2 deletions R/mass_weighted.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
#' w <- mp_toy_data$sub_len
#' ref_data <- mp_toy_data$data[, 1]
#' query_data <- mp_toy_data$data[, 1]
#' weight <- c(rep(1, mp_toy_data$sub_len / 3), rep(0.5, mp_toy_data$sub_len / 3), rep(1, mp_toy_data$sub_len / 3))
#' weight <- c(rep(1, mp_toy_data$sub_len / 3), rep(0.5, mp_toy_data$sub_len / 3),
#' rep(1, mp_toy_data$sub_len / 3))
#'
#' pre <- tsmp:::mass_pre_w(ref_data, query_data, w, weight)
#'
Expand All @@ -39,7 +40,8 @@
#' pre$data_mean, pre$data_sd, pre$data_pre, pre$weight
#' )
#' }
mass_weighted <- function(query_window, window_size, data_fft, data_size, data_mean, data_sd, data_pre, weight, ...) {
mass_weighted <- function(query_window, window_size, data_fft, data_size, data_mean, data_sd,
data_pre, weight, ...) {
if (length(weight) != window_size) {
stop("'weight' must have the same length as the 'window_size'.")
}
Expand Down
12 changes: 7 additions & 5 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#' @param ylab a `string`. (Default is `""`). Y label.
#' @param xlab a `string`. (Default is `"Profile Index"`). X label.
#' @param ... further arguments to be passed to [plot()]. See [par()].
#' @param xmin an `int`. (Default is `NULL`). Set the minimum value of x axis.
#' @param xmax an `int`. (Default is `NULL`). Set the maximum value of x axis.
#'
#' @return None
#' @keywords hplot
Expand Down Expand Up @@ -164,8 +166,8 @@ plot.ArcCount <- function(x, data, type = c("data", "matrix"), exclusion_zone =
if (cac_size < nrow(profile_index)) {
warning("cac_size < profile_index")
cac_offset <- nrow(profile_index) - cac_size
plot_data <- as.matrix(tail(plot_data, cac_size))
profile_index <- as.matrix(tail(profile_index, cac_size) - cac_offset)
plot_data <- as.matrix(utils::tail(plot_data, cac_size))
profile_index <- as.matrix(utils::tail(profile_index, cac_size) - cac_offset)
}

xnum <- seq_len(nrow(x$mp) + min(x$w) - 1)
Expand Down Expand Up @@ -390,7 +392,7 @@ plot.SimpleMatrixProfile <- function(x, ylab = "distance", xlab = "index", main

if (n_dim > 1) {
for (i in 2:n_dim) {
lines(xnum, x$data[[1]][, i], main = paste0("Data"), ylab = "", xlab = xlab, col = i, ...)
graphics::lines(xnum, x$data[[1]][, i], main = paste0("Data"), ylab = "", xlab = xlab, col = i, ...)
}
}

Expand All @@ -402,7 +404,7 @@ plot.SimpleMatrixProfile <- function(x, ylab = "distance", xlab = "index", main

if (n_dim > 1) {
for (i in 2:n_dim) {
lines(xnum, x$data[[2]][, i], main = paste0("Data"), ylab = "", xlab = xlab, col = i, ...)
graphics::lines(xnum, x$data[[2]][, i], main = paste0("Data"), ylab = "", xlab = xlab, col = i, ...)
}
}
}
Expand Down Expand Up @@ -540,7 +542,7 @@ plot.Floss <- function(x, data, type = c("data", "matrix"),
if (cac_fin_len == floor((mp_len * vars()$kmode + new_data / 2))) {
cac <- x$cac_final
} else {
cac <- tail(x$cac_final, -offset)
cac <- utils::tail(x$cac_final, -offset)
}
cac_size <- length(cac)
cac <- c(cac, rep(NA, nrow(x$mp) + min(x$w) - 1 - cac_size))
Expand Down
18 changes: 9 additions & 9 deletions R/stompi.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,24 +95,24 @@ stompi_update <- function(.mp, new_data, history_size = FALSE) {
}

if (history_size && (data_upd_size > history_size)) {
data_upd <- tail(data_upd, history_size)
data_upd <- utils::tail(data_upd, history_size)
mp_new_size <- history_size - .mp$w + 1
offset <- data_upd_size - history_size

mp_new <- tail(mp_new, mp_new_size)
pi_new <- tail(pi_new - offset, mp_new_size)
lmp_new <- tail(lmp_new, mp_new_size)
lpi_new <- tail(lpi_new - offset, mp_new_size)
rmp_new <- tail(rmp_new, mp_new_size)
rpi_new <- tail(rpi_new - offset, mp_new_size)
mp_new <- utils::tail(mp_new, mp_new_size)
pi_new <- utils::tail(pi_new - offset, mp_new_size)
lmp_new <- utils::tail(lmp_new, mp_new_size)
lpi_new <- utils::tail(lpi_new - offset, mp_new_size)
rmp_new <- utils::tail(rmp_new, mp_new_size)
rpi_new <- utils::tail(rpi_new - offset, mp_new_size)

if (is.null(attr(.mp, "offset"))) {
attr(.mp, "offset") <- offset
} else {
attr(.mp, "offset") <- attr(.mp, "offset") + offset
}

# pi_new <- tail(pi_new - attr(.mp, "offset"), mp_new_size)
# pi_new <- utils::tail(pi_new - attr(.mp, "offset"), mp_new_size)
}

.mp$mp <- as.matrix(mp_new)
Expand All @@ -126,7 +126,7 @@ stompi_update <- function(.mp, new_data, history_size = FALSE) {

# TODO: with tail or not (tail will recompute some things)
# if (history_size && (data_upd_size > history_size)) {
# return(tail(.mp, history_size))
# return(utils::tail(.mp, history_size))
# } else {
return(.mp)
# }
Expand Down
Loading

0 comments on commit 5e7e30b

Please sign in to comment.