Running ‘test_fastcluster.R’ [3s/3s]
Running the tests in ‘tests/test_fastcluster.R’ failed.
Complete output:
  > #  fastcluster: Fast hierarchical clustering routines for R and Python
  > #
  > #  Copyright © 2011 Daniel Müllner
  > #  <http://danifold.net>
  > #
  > # Test script for the R interface
  > 
  > seed = as.integer(runif(1, 0, 1e9))
  > set.seed(seed)
  > cat(sprintf("Random seed: %d\n",seed))
  Random seed: 661815213
  > 
  > print_seed <- function() {
  +   return(sprintf('
  + Please send a report to the author of the \'fastcluster\' package, Daniel Müllner.
  + For contact details, see <http://danifold.net>. To make the error
  + reproducible, you must include the following number (the random seed value) in
  + your error report: %d.\n\n', seed))
  + }
  > 
  > hasWardD2 = getRversion() >= '3.1.0'
  > 
  > # Compare two dendrograms and check whether they are equal, except that
  > # ties may be resolved differently.
  > compare <- function(dg1, dg2) {
  +   h1 <- dg1$height
  +   h2 <- dg2$height
  +   # "height" vectors may have small numerical errors.
  +   rdiffs <- abs(h1-h2)/pmax(abs(h1),abs(h2))
  +   rdiffs = rdiffs[complete.cases(rdiffs)]
  +   rel_error <-  max(rdiffs)
  +   # We allow a relative error of 1e-13.
  +   if (rel_error>1e-13) {
  +     print(h1)
  +     print(h2)
  +     cat(sprintf('Height vectors differ! The maximum relative error is %e.\n', rel_error))
  +     return(FALSE)
  +   }
  +   # Filter the indices where consecutive merging distances are distinct.
  +   d = diff(dg1$height)
  +   b = (c(d,1)!=0 & c(1,d)!=0)
  +   #cat(sprintf("Percentage of indices where we can test: %g.\n",100.0*length(b[b])/length(b)))
  +   if (any(b)) {
  +     m1 = dg1$merge[b,]
  +     m2 = dg2$merge[b,]
  + 
  +     r = function(i) {
  +       if (i<0) {
  +         return(1)
  +       }
  +       else {
  +         return(b[i])
  +       }
  +     }
  + 
  +     f = sapply(m1,r)
  +     fm1 = m1*f
  +     fm2 = m2*f
  +     # The "merge" matrices must be identical whereever indices are not ambiguous
  +     # due to ties.
  +     if (!identical(fm1,fm2)) {
  +       cat('Merge matrices differ!\n')
  +       return(FALSE)
  +     }
  +     # Compare the "order" vectors only if all merging distances were distinct.
  +     if (all(b) && !identical(dg1$order,dg2$order)) {
  +       cat('Order vectors differ!\n')
  +       return(FALSE)
  +     }
  +   }
  +   return(TRUE)
  + }
  > 
  > # Generate uniformly distributed random data
  > generate.uniform <- function() {
  +   n = sample(10:1000,1)
  +   range_exp = runif(1,min=-10, max=10)
  +   cat(sprintf("Number of sample points: %d\n",n))
  +   cat(sprintf("Dissimilarity range: [0,%g]\n",10^range_exp))
  +   d = runif(n*(n-1)/2, min=0, max=10^range_exp)
  +   # Fake a compressed distance matrix
  +   attributes(d) <- NULL
  +   attr(d,"Size") <- n
  +   attr(d, "call") <- 'N/A'
  +   class(d) <- "dist"
  +   return(d)
  + }
  > 
  > # Generate normally distributed random data
  > generate.normal <- function() {
  +   n = sample(10:1000,1)
  +   dim = sample(2:20,1)
  + 
  +   cat (sprintf("Number of sample points: %d\n",n))
  +   cat (sprintf("Dimension: %d\n",dim))
  + 
  +   pcd = matrix(rnorm(n*dim), c(n,dim))
  +   d = dist(pcd)
  +   return(d)
  + }
  > 
  > # Test the clustering functions when a distance matrix is given.
  > test.dm <-  function(d) {
  +   d2 = d
  +   if (hasWardD2) {
  +     methods = c('single','complete','average','mcquitty','ward.D','ward.D2','centroid','median')
  +   }
  +   else {
  +     methods = c('single','complete','average','mcquitty','ward','centroid','median')
  +   }
  +   for (method in methods) {
  +     cat(paste('Method :', method, '\n'))
  +     dg_stats       = stats::hclust(d, method=method)
  +     if (method == 'ward') {
  +       method = 'ward.D'
  +     }
  +     dg_fastcluster = fastcluster::hclust(d, method=method)
  +     if (!identical(d,d2)) {
  +       cat('Input array was corrupted!\n')
  +       stop(print_seed())
  +     }
  +     if (!compare(dg_stats, dg_fastcluster)) {
  +       stop(print_seed())
  +     }
  +   }
  +   cat('Passed.\n')
  + }
  > 
  > # Test the clustering functions for vector input in Euclidean space.
  > test.vector <-  function() {
  +   # generate test data
  +   n = sample(10:1000,1)
  +   dim = sample(2:20,1)
  +   cat (sprintf("Number of sample points: %d\n",n))
  +   cat (sprintf("Dimension: %d\n",dim))
  + 
  +   range_exp = runif(1,min=-10, max=10)
  +   pcd = matrix(rnorm(n*dim, sd=10^range_exp), c(n,dim))
  +   pcd2 = pcd
  +   # test
  +   method='single'
  +   cat(paste('Method:', method, '\n'))
  +   for (metric in c('euclidean', 'maximum', 'manhattan', 'canberra', 'minkowski')) {
  +     cat(paste('    Metric:', metric, '\n'))
  +     if (metric=='minkowski') {
  +       p = runif(1, min=1.0, max=10.0)
  +       cat (sprintf("    p: %g\n",p));
  +       dg_fastcluster = fastcluster::hclust.vector(pcd, method=method, metric=metric, p=p)
  +       d = dist(pcd, method=metric, p=p)
  +     }
  +     else {
  +       dg_fastcluster = fastcluster::hclust.vector(pcd, method=method, metric=metric)
  +       d = dist(pcd, method=metric)
  +     }
  +     d2 = d
  +     dg_fastcluster_dist = fastcluster::hclust(d, method=method)
  +     if (!identical(d,d2) || !identical(pcd,pcd2)) {
  +       cat('Input array was corrupted!\n')
  +       stop(print_seed())
  +     }
  +     if (!compare(dg_fastcluster_dist, dg_fastcluster)) {
  +       stop(print_seed())
  +     }
  +   }
  +   for (method in c('ward','centroid','median') ) {
  +     cat(paste('Method:', method, '\n'))
  +     dg_fastcluster = fastcluster::hclust.vector(pcd, method=method)
  +     if (!identical(pcd,pcd2)) {
  +       cat('Input array was corrupted!\n')
  +       stop(print_seed())
  +     }
  +     d = dist(pcd)
  +     if(method == "ward" && hasWardD2) {
  +       method = "ward.D2"
  +     }
  +     else
  +     {
  +       # Workaround: fastcluster::hclust expects _squared_ euclidean distances.
  +       d = d^2
  +     }
  +     d2 = d
  +     dg_fastcluster_dist = fastcluster::hclust(d, method=method)
  +     if (!identical(d,d2)) {
  +       cat('Input array was corrupted!\n')
  +       stop(print_seed())
  +     }
  +     if(method != "ward.D2") {
  +       dg_fastcluster_dist$height = sqrt(dg_fastcluster_dist$height)
  +     }
  +     # The Euclidean methods may have small numerical errors due to squaring/
  +     # taking the root in the Euclidean distances.
  +     if (!compare(dg_fastcluster_dist, dg_fastcluster)) {
  +       stop(print_seed())
  +     }
  +   }
  +   cat('Passed.\n')
  + }
  > 
  > # Test the single linkage function with the "binary" metric
  > test.vector.binary <- function() {
  +   # generate test data
  +   cat (sprintf("Uniform sampling for the 'binary' metric:\n"))
  +   n = sample(10:400,1)
  +   dim = sample(n:(2*n),1)
  +   cat (sprintf("Number of sample points: %d\n",n))
  +   cat (sprintf("Dimension: %d\n",dim))
  +   pcd = matrix(sample(-1:2, n*dim, replace=T), c(n,dim))
  +   pcd2 = pcd
  +   # test
  +   method='single'
  +   metric='binary'
  +   cat(paste('Method:', method, '\n'))
  +   cat(paste('    Metric:', metric, '\n'))
  +   dg_fastcluster = fastcluster::hclust.vector(pcd, method=method, metric=metric)
  +   d = dist(pcd, method=metric)
  +   d2 = d
  +   dg_fastcluster_dist       = fastcluster::hclust(d, method=method)
  +   if (!identical(d,d2) || !identical(d,d2)) {
  +     cat('Input array was corrupted!\n')
  +     stop(print_seed())
  +   }
  +   if (!compare(dg_fastcluster_dist, dg_fastcluster)) {
  +     stop(print_seed())
  +   }
  +   cat('Passed.\n')
  + }
  > 
  > 
  > N = 15
  > for (i in (1:N)) {
  +   if (i%%2==1) {
  +     cat(sprintf('Random test %d of %d (uniform distribution of distances):\n',i,2*N))
  +     d = generate.uniform()
  +   }
  +   else {
  +     cat(sprintf('Random test %d of %d (Gaussian density):\n',i,2*N))
  +     d = generate.normal()
  +   }
  +   test.dm(d)
  + }
  Random test 1 of 30 (uniform distribution of distances):
  Number of sample points: 889
  Dissimilarity range: [0,7.7658e-05]
  Method : single 
  Method : complete 
  Method : average 
  Method : mcquitty 
  Method : ward.D 
  Method : ward.D2 
  Method : centroid 
  Method : median 
  Passed.
  Random test 2 of 30 (Gaussian density):
  Number of sample points: 680
  Dimension: 2
  Method : single 
  Method : complete 
  Method : average 
  Method : mcquitty 
  Method : ward.D 
  Method : ward.D2 
  Method : centroid 
  Method : median 
  Passed.
  Random test 3 of 30 (uniform distribution of distances):
  Number of sample points: 338
  Dissimilarity range: [0,3.3329e-05]
  Method : single 
  Method : complete 
  Method : average 
  Method : mcquitty 
  Method : ward.D 
  Method : ward.D2 
  Method : centroid 
  Method : median 
  Passed.
  Random test 4 of 30 (Gaussian density):
  Number of sample points: 714
  Dimension: 12
  Method : single 
  Method : complete 
  Method : average 
  Method : mcquitty 
  Method : ward.D 
  Method : ward.D2 
  Method : centroid 
  Method : median 
  Passed.
  Random test 5 of 30 (uniform distribution of distances):
  Number of sample points: 471
  Dissimilarity range: [0,314.014]
  Method : single 
  Method : complete 
  Method : average 
  Method : mcquitty 
  Method : ward.D 
  Method : ward.D2 
  Method : centroid 
  Method : median 
  Passed.
  Random test 6 of 30 (Gaussian density):
  Number of sample points: 945
  Dimension: 3
  Method : single 
  Method : complete 
  Method : average 
  Method : mcquitty 
  Method : ward.D 
  Method : ward.D2 
  Method : centroid 
  Method : median 
  Passed.
  Random test 7 of 30 (uniform distribution of distances):
  Number of sample points: 926
  Dissimilarity range: [0,51437]
  Method : single 
  Method : complete 
  Method : average 
  Method : mcquitty 
  Method : ward.D 
  Method : ward.D2 
  Method : centroid 
  Method : median 
  Passed.
  Random test 8 of 30 (Gaussian density):
  Number of sample points: 562
  Dimension: 7
  Method : single 
  Method : complete 
  Method : average 
  Method : mcquitty 
  Method : ward.D 
  Method : ward.D2 
  Method : centroid 
  Method : median 
  Passed.
  Random test 9 of 30 (uniform distribution of distances):
  Number of sample points: 103
  Dissimilarity range: [0,1.49735e-08]
  Method : single 
  Method : complete 
  Method : average 
  Method : mcquitty 
  Method : ward.D 
  Method : ward.D2 
  Method : centroid 
  Method : median 
  Passed.
  Random test 10 of 30 (Gaussian density):
  Number of sample points: 742
  Dimension: 5
  Method : single 
  Method : complete 
  Method : average 
  Method : mcquitty 
  Method : ward.D 
  Method : ward.D2 
  Method : centroid 
  Method : median 
  Passed.
  Random test 11 of 30 (uniform distribution of distances):
  Number of sample points: 936
  Dissimilarity range: [0,3.43051e-08]
  Method : single 
  Method : complete 
  Method : average 
  Method : mcquitty 
  Method : ward.D 
  Method : ward.D2 
  Method : centroid 
  Method : median 
  Passed.
  Random test 12 of 30 (Gaussian density):
  Number of sample points: 223
  Dimension: 17
  Method : single 
  Method : complete 
  Method : average 
  Method : mcquitty 
  Method : ward.D 
  Method : ward.D2 
  Method : centroid 
  Method : median 
  Passed.
  Random test 13 of 30 (uniform distribution of distances):
  Number of sample points: 17
  Dissimilarity range: [0,2.40061e+06]
  Method : single 
  Method : complete 
  Method : average 
  Method : mcquitty 
  Method : ward.D 
  Method : ward.D2 
  Method : centroid 
  Method : median 
  Passed.
  Random test 14 of 30 (Gaussian density):
  Number of sample points: 674
  Dimension: 19
  Method : single 
  Method : complete 
  Method : average 
  Method : mcquitty 
  Method : ward.D 
  Method : ward.D2 
  Method : centroid 
  Method : median 
  Passed.
  Random test 15 of 30 (uniform distribution of distances):
  Number of sample points: 469
  Dissimilarity range: [0,0.000107393]
  Method : single 
  Method : complete 
  Method : average 
  Method : mcquitty 
  Method : ward.D 
  Method : ward.D2 
  Method : centroid 
  Method : median 
  Passed.
  > for (i in (N+1:N)) {
  +   cat(sprintf('Random test %d of %d (Gaussian density):\n',i,2*N))
  +   test.vector()
  +   test.vector.binary()
  + }
  Random test 16 of 30 (Gaussian density):
  Number of sample points: 135
  Dimension: 9
  Method: single 
      Metric: euclidean 
      Metric: maximum 
      Metric: manhattan 
      Metric: canberra 
    [1] 2.381397 2.485147 2.664050 2.670183 2.671746 2.757571 2.782666 2.794775
    [9] 2.863436 2.890121 2.905075 3.023206 3.093425 3.093987 3.176300 3.186974
   [17] 3.194551 3.194749 3.202914 3.222470 3.227552 3.286818 3.293005 3.310820
   [25] 3.374289 3.399152 3.406757 3.420331 3.436186 3.446789 3.455438 3.468350
   [33] 3.493748 3.497752 3.510595 3.554074 3.571736 3.584136 3.589358 3.599493
   [41] 3.609396 3.617301 3.626232 3.627503 3.644654 3.650226 3.653308 3.653888
   [49] 3.657178 3.683138 3.689956 3.700070 3.701412 3.710350 3.711362 3.728154
   [57] 3.733321 3.749133 3.752794 3.763790 3.764696 3.766382 3.783835 3.793860
   [65] 3.805178 3.810599 3.837088 3.847634 3.847935 3.854489 3.860920 3.862701
   [73] 3.872307 3.872900 3.886310 3.894841 3.897951 3.900180 3.911774 3.911859
   [81] 3.917935 3.922289 3.926226 3.942296 3.945930 3.962210 3.962242 3.968575
   [89] 3.981876 3.983131 3.984110 3.992800 3.996857 3.997520 3.998636 4.020289
   [97] 4.028199 4.037047 4.041597 4.045493 4.050254 4.061985 4.089431 4.099244
  [105] 4.103624 4.125548 4.127351 4.129084 4.160730 4.165048 4.169455 4.171754
  [113] 4.178622 4.182348 4.189289 4.196136 4.214218 4.240537 4.251288 4.263994
  [121] 4.273029 4.278506 4.313027 4.314834 4.358918 4.363322 4.364923 4.366225
  [129] 4.367352 4.434583 4.462251 4.521404 4.568832 5.141285
    [1] 2.782666 3.093987 3.194551 3.291021 3.337702 3.396205 3.468350 3.510595
    [9] 3.520577 3.541289 3.720296 3.762870 3.797229 3.848768 3.910214 3.943608
   [17] 3.943845 3.949837 3.963284 4.036710 4.041597 4.045493 4.059733 4.140510
   [25] 4.182348 4.200002 4.220158 4.220972 4.407006 4.480531 4.492306 4.493059
   [33] 4.499775 4.509822 4.537177 4.560055 4.565573 4.598518 4.609356 4.614575
   [41] 4.630354 4.639234 4.646404 4.657134 4.677537 4.686141 4.696642 4.708369
   [49] 4.718268 4.736335 4.736472 4.740599 4.760165 4.775514 4.780990 4.810762
   [57] 4.814792 4.829905 4.832587 4.850208 4.874664 4.875260 4.903591 4.913154
   [65] 4.914100 4.919444 4.939692 4.945362 4.949063 4.960084 4.984949 5.006181
   [73] 5.012635 5.024490 5.030190 5.033205 5.071431 5.127424 5.133064 5.144069
   [81] 5.155542 5.181405 5.190939 5.202359 5.210856 5.214995 5.265587 5.278434
   [89] 5.310268 5.346148 5.365215 5.377974 5.446154 5.449967 5.459267 5.481042
   [97] 5.493364 5.540839 5.599823 5.606865 5.610464 5.612722 5.634705 5.635882
  [105] 5.638945 5.642823 5.654418 5.704782 5.786756 5.788324 5.819135 5.832066
  [113] 5.837784 5.838003 5.921774 5.947421 5.953466 5.955331 5.970256 5.994993
  [121] 6.008779 6.016170 6.018222 6.113302 6.170205 6.182864 6.316908 6.341682
  [129] 6.342712 6.382333 6.432971 6.469847 6.942171 7.445737
  Height vectors differ! The maximum relative error is 3.418728e-01.
  Error in test.vector() : 
  Please send a report to the author of the 'fastcluster' package, Daniel Müllner.
  For contact details, see <http://danifold.net>. To make the error
  reproducible, you must include the following number (the random seed value) in
  your error report: 661815213.
  
  Execution halted