Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

https://github.com/cran/dtw
28 September 2022, 07:50:27 UTC
  • Code
  • Branches (54)
  • Releases (0)
  • Visits
    • Branches
    • Releases
    • HEAD
    • refs/heads/master
    • refs/tags/0.1-2
    • refs/tags/0.3-1
    • refs/tags/0.4-2
    • refs/tags/1.0-2
    • refs/tags/1.12-3
    • refs/tags/1.12-5
    • refs/tags/1.13-1
    • refs/tags/1.14-1
    • refs/tags/1.14-3
    • refs/tags/1.15
    • refs/tags/1.16
    • refs/tags/1.17-1
    • refs/tags/1.18-1
    • refs/tags/1.2-1
    • refs/tags/1.20-1
    • refs/tags/1.21-1
    • refs/tags/1.21-3
    • refs/tags/1.22-3
    • refs/tags/1.23-1
    • refs/tags/1.4-3
    • refs/tags/1.5-3
    • refs/tags/1.6-2
    • refs/tags/1.9-1
    • refs/tags/R-2.10.0
    • refs/tags/R-2.10.1
    • refs/tags/R-2.11.0
    • refs/tags/R-2.11.1
    • refs/tags/R-2.12.0
    • refs/tags/R-2.12.1
    • refs/tags/R-2.12.2
    • refs/tags/R-2.13.0
    • refs/tags/R-2.13.1
    • refs/tags/R-2.13.2
    • refs/tags/R-2.14.0
    • refs/tags/R-2.14.1
    • refs/tags/R-2.14.2
    • refs/tags/R-2.15.0
    • refs/tags/R-2.15.1
    • refs/tags/R-2.15.2
    • refs/tags/R-2.15.3
    • refs/tags/R-2.6.2
    • refs/tags/R-2.7.0
    • refs/tags/R-2.7.1
    • refs/tags/R-2.7.2
    • refs/tags/R-2.8.0
    • refs/tags/R-2.8.1
    • refs/tags/R-2.9.0
    • refs/tags/R-2.9.1
    • refs/tags/R-2.9.2
    • refs/tags/R-3.0.0
    • refs/tags/R-3.0.1
    • refs/tags/R-3.0.2
    • refs/tags/R-3.0.3
    No releases to show
  • ea7676e
  • /
  • man
  • /
  • dtwDist.Rd
Raw File Download
Take a new snapshot of a software origin

If the archived software origin currently browsed is not synchronized with its upstream version (for instance when new commits have been issued), you can explicitly request Software Heritage to take a new snapshot of it.

Use the form below to proceed. Once a request has been submitted and accepted, it will be processed as soon as possible. You can then check its processing state by visiting this dedicated page.
swh spinner

Processing "take a new snapshot" request ...

Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
  • revision
  • snapshot
origin badgecontent badge Iframe embedding
swh:1:cnt:43cfc97e2fcc6caa1de0ecbf5948215180b41234
origin badgedirectory badge Iframe embedding
swh:1:dir:e8cd71f2b3c169805414f7c805c60d695ebfb79d
origin badgerevision badge
swh:1:rev:935e521fa862c893e52a85dbb72c3ae53246a8e4
origin badgesnapshot badge
swh:1:snp:e75a8a2617c9395688cff068aec5b1e7448d2a41
Citations

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
  • revision
  • snapshot
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Tip revision: 935e521fa862c893e52a85dbb72c3ae53246a8e4 authored by Toni Giorgino on 15 August 2009, 00:00:00 UTC
version 1.14-3
Tip revision: 935e521
dtwDist.Rd
\name{dtwDist}
\alias{dtwDist}
\title{Compute a dissimilarity matrix}

\description{Compute the dissimilarity matrix  between
  a set of single-variate timeseries.  }

\usage{
dtwDist(mx,my=mx,...)
# dist(mx,my=mx,method="DTW",...)
}
\arguments{
  \item{mx}{numeric matrix, containing timeseries as rows}
  \item{my}{numeric matrix, containing timeseries as rows (for cross-distance)}
  \item{...}{arguments passed to the \code{\link{dtw}} call}
}

\value{
 A square matrix whose element \code{[i,j]} holds the Dynamic Time Warp
 distance between row \code{i} (query) and \code{j} (reference) of
 \code{mx} and \code{my}, i.e.  \code{dtw(mx[i,],my[j,])$distance}.
}

\details{

  \code{dtwDist} computes a dissimilarity matrix, akin to
  \code{\link{dist}}, based on the Dynamic Time Warping definition of a
  distance between single-variate timeseries.


  The \code{dtwDist} command is a synonym for the
  \code{\link[proxy]{dist}} function of package \pkg{proxy}; the DTW
  distance is registered as \code{method="DTW"} (see examples below).

  The timeseries are stored as rows in the matrix argument \code{m}. In
  other words, if \code{m} is an N * T matrix, \code{dtwDist} will build
  N*N ordered pairs of timeseries, perform the corresponding N*N
  \code{dtw} alignments, and return all of the results in a matrix. Each
  of the timeseries is T elements long.

  \code{dtwDist} returns a square matrix, whereas the \code{dist} object
  is lower-triangular. This makes sense because in general the DTW
  "distance" is not symmetric (see e.g.  asymmetric step patterns).  To
  make a square matrix with the \code{\link[proxy]{dist}} function
  sematics, use the two-arguments call as \code{dist(m,m)}. This will
  return a square \code{crossdist} object.  }

\note{
  To convert a square cross-distance matrix (\code{crossdist} object) to
  a symmetric \code{\link{dist}} object, use a suitable conversion
  strategy (see examples).
}


\seealso{Other "distance" functions are: \code{\link{dist}},
  \code{\link[vegan]{vegdist}} in package \code{vegan},
  \code{\link[analogue]{distance}} in package \code{analogue}, etc.
}

\examples{

## Symmetric step pattern => symmetric dissimilarity matrix;
## no problem coercing it to a dist object:

m <- matrix(0,ncol=3,nrow=4)
m <- row(m)
dist(m,method="DTW");

# Old-fashioned call style would be:
#   dtwDist(m)
#   as.dist(dtwDist(m))



## Find the optimal warping _and_ scale factor at the same time.
## (There may be a better, analytic way)

# Prepare a query and a reference

query<-sin(seq(0,4*pi,len=100))
reference<-cos(seq(0,4*pi,len=100))

# Make a set of several references, scaled from 0 to 3 in .1 increments.
# Put them in a matrix, in rows

scaleSet <- seq(0.1,3,by=.1)
referenceSet<-outer(1/scaleSet,reference)

# The query has to be made into a 1-row matrix.
# Perform all of the alignments at once, and normalize the result.

dist(t(query),referenceSet,meth="DTW")->distanceSet

# The optimal scale for the reference is 1.0
plot(scaleSet,scaleSet*distanceSet,
  xlab="Reference scale factor (denominator)",
  ylab="DTW distance",type="o",
  main="Sine vs scaled cosine alignment, 0 to 4 pi")





## Asymmetric step pattern: we can either disregard part of the pairs
## (as.dist), or average with the transpose

mm <- matrix(runif(12),ncol=3)
dm <- dist(mm,mm,method="DTW",step=asymmetric); # a crossdist object

# Old-fashioned call style would be:
#   dm <- dtwDist(mm,step=asymmetric)
#   as.dist(dm)


## Symmetrize by averaging:
(dm+t(dm))/2


## check definition
stopifnot(dm[2,1]==dtw(mm[2,],mm[1,],step=asymmetric)$distance)


}

\author{Toni Giorgino}
\keyword{ts}

back to top

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Contact— JavaScript license information— Web API