Learn R Programming

dtwSat (version 0.2.7)

twdtwReduceTime: Minimalist version of TWDTW apply

Description

This function is a minimalist implementation of twdtwApply that is in average 3x faster. It does not keep any intermediate data. It performs a multidimensional TWDTW analysis Maus:2019dtwSat and retrieves only the best matches between the unclassified time series and the patterns for each defined time interval.

Usage

twdtwReduceTime(
  x,
  y,
  weight.fun = NULL,
  dist.method = "Euclidean",
  step.matrix = symmetric1,
  from = NULL,
  to = NULL,
  by = NULL,
  overlap = 0.5,
  fill = 255
)

Arguments

x

a data.frame with the target time series. Usually, it is an unclassified time series. It must contain two or more columns, one column called date with dates in the format "YYYY-MM-DD". The other columns can have any names (e.g., red, blue, nir, evi, ndvi) as long as they match the column names in the temporal patterns y.

y

a list of data.frame objects similar to x. The temporal patterns used to classify the time series in x.

weight.fun

A function. Any function that receives two matrices and performs a computation on them, returning a single matrix with the same dimensions. The first matrix is the DTW local cost matrix and the second a matrix of the time differences in days. The function should return a matrix of DTW local cost weighted by the time differences. If not declared the time-weight is zero. In this case the function runs the standard version of the dynamic time warping. See details.

dist.method

A character. Method to derive the local cost matrix. Default is ''Euclidean'' see dist in package proxy.

step.matrix

See stepPattern in package dtw Giorgino:2009dtwSat.

from

A character or Dates object in the format "yyyy-mm-dd".

to

A character or Dates object in the format "yyyy-mm-dd".

by

A character with the interval size, e.g. "6 month".

overlap

A number between 0 and 1. The minimum overlapping between one match and the interval of classification. Default is 0.5, i.e. an overlap minimum of 50%.

fill

An integer to fill the classification gaps. Default 255.

Author

Victor Maus, vwmaus1@gmail.com

Examples

Run this code
if (FALSE) {

library(dtwSat)
log_fun = logisticWeight(-0.1, 50)
from = "2009-09-01"
to = "2017-09-01"
by = "12 month"

# S4 objects for original implementation 
tw_patt = readRDS(system.file("lucc_MT/patterns/patt.rds", package = "dtwSat"))
tw_ts = twdtwTimeSeries(MOD13Q1.ts) 

# Table from csv for minimalist version 
mn_patt <- lapply(dir(system.file("lucc_MT/patterns", package = "dtwSat"), 
  pattern = ".csv$", full.names = TRUE), read.csv, stringsAsFactors = FALSE)
mn_ts <- read.csv(system.file("reduce_time/ts_MODIS13Q1.csv", package = "dtwSat"), 
  stringsAsFactors = FALSE)

# Benchtmark 
rbenchmark::benchmark(
  original = twdtwClassify(twdtwApply(x = tw_ts, y = tw_patt, weight.fun = log_fun), 
                                      from = from, to = to, by = by)[[1]],
  minimalist = twdtwReduceTime(x = mn_ts, y = mn_patt, weight.fun = log_fun, 
                                      from = from, to = to, by = by)  
 )
}

Run the code above in your browser using DataLab