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

  • d2145b1
  • /
  • tests
  • /
  • dtw_test.R
Raw File Download
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
content badge Iframe embedding
swh:1:cnt:f65f417cc9a9bcf6e6e5146ceb310724daa49f19
directory badge Iframe embedding
swh:1:dir:f5ea635a918e0bbc9454243e605092da06a62239
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
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
dtw_test.R
library(dtw);

### Synthetic example: check indexes, distance
ldist<-matrix(1,nrow=6,ncol=6);  # Matrix of ones
ldist[2,]<-0; ldist[,5]<-0;      # Mark a clear path of zeroes
ldist[2,5]<-.01;		 # Forcely cut the corner

ds<-dtw(ldist);			 # DTW with user-supplied local cost matrix
ds$distance			 # 2
ds$index1			 # 1 2 2 2 2 3 4 5 6 6
ds$index2			 # 1 1 2 3 4 5 5 5 5 6

da<-dtw(ldist,step="a");	 # Also compute the asymmetric
da$distance			 # 2
da$index1			 # 1 2 3 4 5 6
da$index2			 # 1 3 5 5 5 6

da<-dtw(ldist,step=asymmetricP0);	 # The strange aP0 alignment
da$distance			 # 1
da$index1			 # 1 2 2 2 2 3 4 5 6 6
da$index2			 # 1 1 2 3 4 5 5 5 5 6

ds<- globalCostMatrix(ldist)
dsn<- globalCostMatrix(ldist,native=FALSE)
stopifnot(all.equal(ds,dsn))		 # TRUE


###  Sine/cosine example: verify native output
### there may be a random chance of failing due to rounding errors
idx<-seq(0,6.28,len=100);
query<-sin(idx)+runif(100)/10;	
template<-cos(idx)
ldist<-outer(query,template,FUN=function(x,y){(x-y)^2})
ds<- globalCostMatrix(ldist)
dsn<- globalCostMatrix(ldist,native=FALSE)
all.equal(ds,dsn)		# TRUE

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

back to top