Description Usage Arguments Value References Examples
View source: R/functional_hclust.R
Given N curves γ_1 (t), γ_2 (t), …, γ_N (t) : I \rightarrow \mathbf{R}, perform hierarchical agglomerative clustering with fastcluster package's implementation of the algorithm. Dissimilarity for curves is measured by L_p metric.
1 2 3 4 5 6 7 |
fdobj |
a |
p |
an exponent in L_p formalism (default: 2). |
method |
agglomeration method to be used. This must be one of |
members |
|
an object of class hclust
. See hclust
for details.
ferreira_comparison_2009T4cluster
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | # -------------------------------------------------------------
# two types of curves
#
# type 1 : sin(x) + perturbation; 20 OF THESE ON [0, 2*PI]
# type 2 : cos(x) + perturbation; 20 OF THESE ON [0, 2*PI]
# -------------------------------------------------------------
## PREPARE : USE 'fda' PACKAGE
# Generate Raw Data
datx = seq(from=0, to=2*pi, length.out=100)
daty = array(0,c(100, 40))
for (i in 1:20){
daty[,i] = sin(datx) + rnorm(100, sd=0.1)
daty[,i+20] = cos(datx) + rnorm(100, sd=0.1)
}
# Wrap as 'fd' object
mybasis <- fda::create.bspline.basis(c(0,2*pi), nbasis=10)
myfdobj <- fda::smooth.basis(datx, daty, mybasis)$fd
## RUN THE ALGORITHM
hcsingle = funhclust(myfdobj, method="single")
## VISUALIZE
opar <- par(no.readonly=TRUE)
par(mfrow=c(1,3))
matplot(datx, daty[,1:20], type="l", main="Curves Type 1")
matplot(datx, daty[,21:40], type="l", main="Curves Type 2")
plot(hcsingle, main="hclust with 'single' linkage")
par(opar)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.