File: ellipsoid-ex.R

package info (click to toggle)
cluster 2.1.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,728 kB
  • sloc: ansic: 3,397; sh: 20; makefile: 2
file content (34 lines) | stat: -rw-r--r-- 1,103 bytes parent folder | download | duplicates (3)
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
29
30
31
32
33
34
library(cluster)

tools::assertWarning(eh <- ellipsoidhull(cbind(x=1:4, y = 1:4)), verbose=TRUE) #singular
eh ## center ok, shape "0 volume" --> Warning
stopifnot(volume(eh) == 0)

set.seed(157)
for(n in 4:10) { ## n=2 and 3 still differ -- platform dependently!
    cat("n = ",n,"\n")
    x2 <- rnorm(n)
    print(ellipsoidhull(cbind(1:n, x2)))
    print(ellipsoidhull(cbind(1:n, x2, 4*x2 + rnorm(n))))
}

set.seed(1)
x <- rt(100, df = 4)
y <- 100 + 5 * x + rnorm(100)
ellipsoidhull(cbind(x,y))
z <- 10  - 8 * x + y + rnorm(100)
(e3 <- ellipsoidhull(cbind(x,y,z)))
d3o <- cbind(x,y + rt(100,3), 2 * x^2 + rt(100, 2))
(e. <- ellipsoidhull(d3o, ret.sq = TRUE))
stopifnot(all.equal(e.$sqdist,
		    with(e., mahalanobis(d3o, center=loc, cov=cov)),
		    tol = 1e-13))
d5 <- cbind(d3o, 2*abs(y)^1.5 + rt(100,3), 3*x - sqrt(abs(y)))
(e5 <- ellipsoidhull(d5, ret.sq = TRUE))
tail(sort(e5$sqdist)) ## 4 values 5.00039 ... 5.0099

(e5.1e77 <- ellipsoidhull(1e77*d5))
stopifnot(# proof correct scaling c^5
    all.equal(volume(e5.1e77, log=TRUE) - volume(e5, log=TRUE),
              ncol(d5) *  77* log(10))
)