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: 635674061
  > 
  > 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: 539
  Dissimilarity range: [0,36814.7]
  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: 426
  Dimension: 6
  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: 392
  Dissimilarity range: [0,1.72483e-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: 293
  Dimension: 4
  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: 221
  Dissimilarity range: [0,1.97973e-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: 462
  Dimension: 10
  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: 607
  Dissimilarity range: [0,0.00171578]
  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: 813
  Dimension: 2
  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: 615
  Dissimilarity range: [0,0.00037545]
  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: 216
  Dimension: 20
  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: 452
  Dissimilarity range: [0,6.12128e+07]
  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: 685
  Dimension: 19
  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: 546
  Dissimilarity range: [0,1.36441e+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: 622
  Dimension: 9
  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: 746
  Dissimilarity range: [0,2.7097e+07]
  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: 83
  Dimension: 19
  Method: single 
      Metric: euclidean 
      Metric: maximum 
      Metric: manhattan 
      Metric: canberra 
   [1]  8.827143  9.138134  9.262412  9.424842  9.469247  9.571615  9.660204
   [8]  9.671404  9.725278  9.761737  9.796321  9.843529  9.844551  9.915081
  [15]  9.920176  9.922670  9.928298  9.939603  9.959811 10.058787 10.065573
  [22] 10.071774 10.106514 10.108243 10.115651 10.129942 10.135668 10.146872
  [29] 10.159072 10.168312 10.203995 10.215404 10.219524 10.236513 10.260250
  [36] 10.282414 10.298512 10.300749 10.319562 10.328827 10.342412 10.359970
  [43] 10.362079 10.371962 10.389400 10.419282 10.469297 10.473476 10.482462
  [50] 10.486325 10.497884 10.512330 10.529754 10.537609 10.539778 10.550044
  [57] 10.556248 10.559611 10.570674 10.577156 10.602320 10.604677 10.643387
  [64] 10.653010 10.672308 10.674646 10.694273 10.739753 10.871167 10.908906
  [71] 10.992445 11.137977 11.216803 11.223470 11.223739 11.234812 11.326178
  [78] 11.619655 11.790997 11.816727 12.029388 12.208569
   [1] 11.72285 12.37728 12.41937 12.78402 12.90557 12.90767 12.97476 13.12897
   [9] 13.26644 13.33981 13.76967 13.95481 13.99263 14.27743 14.71249 15.12509
  [17] 15.39481 15.45285 15.46263 15.64530 15.65101 15.68679 15.70067 15.70149
  [25] 15.72885 15.76315 15.92434 16.02455 16.09744 16.23268 16.23616 16.33267
  [33] 16.38555 16.40347 16.45350 16.50268 16.52274 16.52572 16.54059 16.66753
  [41] 16.69054 16.70782 16.72369 16.80758 16.86893 16.87893 16.93643 16.93771
  [49] 17.00760 17.05259 17.21148 17.24724 17.34481 17.39533 17.42796 17.44110
  [57] 17.49045 17.55300 17.59098 17.61313 17.66592 17.74791 17.79708 17.84893
  [65] 17.86736 17.98299 18.05645 18.12586 18.19784 18.30795 18.65371 18.69458
  [73] 18.98361 19.70787 19.87697 19.95824 19.97744 20.67080 20.93764 22.19676
  [81] 22.39909 23.29950
  Height vectors differ! The maximum relative error is 4.760159e-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: 635674061.
  
  Execution halted