Running ‘test_fastcluster.R’ [2s/2s]
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: 696127180
  > 
  > 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: 82
  Dissimilarity range: [0,4889.36]
  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: 958
  Dimension: 16
  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: 13
  Dissimilarity range: [0,1.01208e-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: 265
  Dimension: 19
  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: 374
  Dissimilarity range: [0,1.32882e-07]
  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: 525
  Dimension: 14
  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: 233
  Dissimilarity range: [0,1.63138e+07]
  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: 295
  Dimension: 10
  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: 802
  Dissimilarity range: [0,5.33719e+07]
  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: 169
  Dimension: 8
  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: 418
  Dissimilarity range: [0,0.381421]
  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: 304
  Dimension: 14
  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: 262
  Dissimilarity range: [0,7.92461]
  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: 766
  Dimension: 20
  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: 770
  Dissimilarity range: [0,0.138104]
  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: 142
  Dimension: 16
  Method: single 
      Metric: euclidean 
      Metric: maximum 
      Metric: manhattan 
      Metric: canberra 
    [1] 6.228822 6.448021 6.684724 6.705714 6.743339 6.758738 6.781442 7.051325
    [9] 7.206688 7.210936 7.247928 7.269222 7.270358 7.332300 7.337564 7.337760
   [17] 7.346056 7.369564 7.378270 7.387100 7.394625 7.398343 7.402303 7.418948
   [25] 7.424492 7.491125 7.532046 7.567316 7.576311 7.588569 7.606040 7.608693
   [33] 7.628847 7.650318 7.659912 7.662707 7.692493 7.695749 7.716593 7.733140
   [41] 7.738793 7.739326 7.785799 7.807123 7.812396 7.827315 7.867741 7.880345
   [49] 7.893556 7.894192 7.918886 7.920023 7.932834 7.958572 7.966318 7.973511
   [57] 7.987263 7.995996 7.996213 7.996952 7.996989 7.997938 8.007173 8.022158
   [65] 8.025877 8.036605 8.048307 8.049813 8.055153 8.055789 8.061162 8.061351
   [73] 8.073641 8.074884 8.076926 8.091514 8.106281 8.109356 8.115869 8.118774
   [81] 8.136896 8.143352 8.150392 8.157523 8.163570 8.185758 8.191838 8.192801
   [89] 8.202346 8.206035 8.206472 8.210047 8.213470 8.215115 8.219430 8.222016
   [97] 8.241928 8.244873 8.265238 8.270506 8.286617 8.290634 8.292104 8.297850
  [105] 8.309211 8.324074 8.329485 8.340262 8.350142 8.357266 8.361008 8.375715
  [113] 8.393322 8.400529 8.418909 8.421548 8.432332 8.437404 8.457936 8.477324
  [121] 8.506826 8.541142 8.569397 8.583576 8.585030 8.590831 8.597027 8.630094
  [129] 8.649078 8.664094 8.670486 8.700590 8.701899 8.769720 8.793080 8.816497
  [137] 8.880540 8.961657 9.117767 9.529744 9.732986
    [1]  7.925247  8.032131  8.128518  8.634216  8.763673  8.799586  8.968864
    [8]  9.200829  9.291975  9.508502  9.588704  9.725286  9.818442 10.090808
   [15] 10.195855 10.423054 10.423251 10.432027 10.526515 10.599049 10.623972
   [22] 10.722575 10.740481 10.773346 10.810762 10.814555 10.826125 10.909771
   [29] 10.963273 10.972028 10.992306 11.003529 11.005555 11.054005 11.068169
   [36] 11.096950 11.172220 11.258415 11.289614 11.307862 11.316291 11.375428
   [43] 11.413079 11.509657 11.545334 11.586313 11.608634 11.619950 11.631945
   [50] 11.649692 11.672855 11.703363 11.704556 11.750404 11.798667 11.822661
   [57] 11.833334 11.884626 11.953713 12.150805 12.165951 12.167677 12.170835
   [64] 12.192313 12.218645 12.242580 12.256931 12.260428 12.272008 12.318261
   [71] 12.333609 12.431940 12.447800 12.468105 12.470170 12.500327 12.529641
   [78] 12.534288 12.561035 12.565165 12.606795 12.608912 12.614267 12.660239
   [85] 12.748518 12.775122 12.792204 12.805492 12.884420 12.886469 12.941129
   [92] 12.942774 12.966475 13.010522 13.050620 13.118521 13.144836 13.165911
   [99] 13.203417 13.260361 13.303632 13.311063 13.324568 13.333379 13.360874
  [106] 13.372369 13.373420 13.421814 13.449713 13.523010 13.589146 13.618742
  [113] 13.647764 13.655554 13.675245 13.676050 13.723386 13.814379 13.828243
  [120] 13.980406 14.004975 14.064777 14.316864 14.347336 14.445943 14.450150
  [127] 14.457437 14.577039 14.640619 14.749123 14.928412 15.044543 15.091781
  [134] 15.175054 15.193261 15.363058 15.438133 15.942325 16.048982 16.142327
  [141] 16.301291
  Height vectors differ! The maximum relative error is 4.378701e-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: 696127180.
  
  Execution halted