Skip to content

Commit

Permalink
generalize twdtwCrossValidate for any DTW approach
Browse files Browse the repository at this point in the history
  • Loading branch information
vwmaus committed Mar 17, 2017
1 parent da00c14 commit 3d5f37d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion R/twdtwApply.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
setGeneric(name = "twdtwApply",
def = function(x, y, resample=TRUE, length=NULL, weight.fun=NULL,
dist.method="Euclidean", step.matrix = symmetric1, n=NULL,
span=NULL, min.length=0.5, theta = 0.5, ...) standardGeneric("twdtwApply"))
span=NULL, min.length=0, theta = 0.5, ...) standardGeneric("twdtwApply"))


#' @rdname twdtwApply
Expand Down
7 changes: 6 additions & 1 deletion R/twdtwCrossValidate.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ twdtwCrossValidate.twdtwTimeSeries = function(object, times, p, ...){
validation_ts = subset(object, -I)
patt = createPatterns(training_ts, ...)
twdtw_res = twdtwApply(x = validation_ts, y = patt, n=1, ...)
df = do.call("rbind", lapply(twdtw_res[], function(xx) xx[which.min(xx$distance),]) )
df = do.call("rbind", lapply(twdtw_res[], function(xx) {
i = which.min(xx$distance)
if(length(i)<1)
return(data.frame(Alig.N=NA, from=NA, to=NA, distance=NA, label = "Unclassified"))
xx[i,]
}))
ref = labels(twdtw_res)$timeseries
pred = df$label
data = data.frame(.adjustFactores(ref, pred, levels=NULL, labels=NULL), df[,!names(df)%in%"labels"])
Expand Down

0 comments on commit 3d5f37d

Please sign in to comment.