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: 759872665
  > 
  > 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: 290
  Dissimilarity range: [0,4.16782e-09]
  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: 120
  Dimension: 19
  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: 800
  Dissimilarity range: [0,4.08585e-07]
  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: 250
  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: 192
  Dissimilarity range: [0,4.6331e-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: 835
  Dimension: 18
  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: 923
  Dissimilarity range: [0,1.0097e-06]
  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: 91
  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: 627
  Dissimilarity range: [0,3554.89]
  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: 931
  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: 454
  Dissimilarity range: [0,1.5873e+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: 14
  Dimension: 8
  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: 236
  Dissimilarity range: [0,0.00658237]
  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: 964
  Dimension: 8
  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: 189
  Dissimilarity range: [0,21.6396]
  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: 171
  Dimension: 3
  Method: single 
      Metric: euclidean 
      Metric: maximum 
      Metric: manhattan 
      Metric: canberra 
    [1] 0.07098028 0.09110502 0.20198050 0.21617533 0.21748952 0.23131370
    [7] 0.24077829 0.24365215 0.25210960 0.26870666 0.27273584 0.27663502
   [13] 0.28345761 0.28494840 0.28743939 0.29551058 0.30129145 0.30294204
   [19] 0.30465996 0.30504748 0.30854411 0.31973663 0.32806983 0.33279908
   [25] 0.33897594 0.34121354 0.34449136 0.34780622 0.35233817 0.35992824
   [31] 0.36637211 0.36661615 0.37627175 0.38440357 0.39222817 0.40039923
   [37] 0.40892117 0.41431613 0.41588018 0.41928905 0.42243817 0.42955452
   [43] 0.43273324 0.43342189 0.43511275 0.43523740 0.43798107 0.43965873
   [49] 0.44091386 0.44542060 0.44760787 0.44806070 0.45170041 0.45463308
   [55] 0.45701375 0.45742055 0.45884182 0.46026764 0.46079388 0.46462015
   [61] 0.46957464 0.47194125 0.47306775 0.47836431 0.47873180 0.47931354
   [67] 0.48055789 0.48590787 0.49143947 0.49180719 0.52144629 0.52423822
   [73] 0.52590957 0.53223173 0.53321057 0.53458943 0.53629680 0.53719725
   [79] 0.54042624 0.54455214 0.55804631 0.57256072 0.57500289 0.57658517
   [85] 0.57766912 0.57785594 0.58366002 0.58406680 0.58879102 0.59237679
   [91] 0.59397934 0.59436536 0.59879112 0.60556415 0.61032523 0.61812737
   [97] 0.62034707 0.62365185 0.62731643 0.63113137 0.64926511 0.65536232
  [103] 0.65575449 0.66126594 0.68368862 0.70657599 0.70962965 0.71868287
  [109] 0.72362861 0.72384867 0.74617987 0.74690370 0.75629692 0.76448624
  [115] 0.77338741 0.78122041 0.78448374 0.79098573 0.81543698 0.81830741
  [121] 0.81906941 0.82093162 0.82344497 0.83395768 0.83496464 0.83530825
  [127] 0.83571872 0.85664210 0.88448412 0.89078363 0.89319635 0.89381842
  [133] 0.91167761 0.91847387 0.91877486 0.92453621 0.92867231 0.93649656
  [139] 0.95628313 0.96523816 0.96677222 1.01554972 1.01977018 1.02060339
  [145] 1.02889679 1.03303334 1.03625921 1.03996611 1.04061431 1.04412023
  [151] 1.04683536 1.04918562 1.05960693 1.06091572 1.06379698 1.06576056
  [157] 1.06968206 1.08523531 1.09102315 1.10480411 1.11377045 1.12402021
  [163] 1.13657027 1.15872851 1.17641447 1.20509689 1.23498984 1.54244234
  [169] 1.72956492 1.90633993
    [1] 0.07098028 0.09110502 0.20198050 0.21617533 0.21748952 0.23131370
    [7] 0.24077829 0.24365215 0.25210960 0.26870666 0.27273584 0.27663502
   [13] 0.28345761 0.28494840 0.28743939 0.29551058 0.30129145 0.30294204
   [19] 0.30465996 0.30504748 0.30854411 0.31973663 0.32806983 0.33279908
   [25] 0.33897594 0.34121354 0.34449136 0.34780622 0.35233817 0.35992824
   [31] 0.36637211 0.36661615 0.37627175 0.38440357 0.39222817 0.40039923
   [37] 0.40892117 0.41431613 0.41588018 0.41928905 0.42243817 0.42955452
   [43] 0.43273324 0.43342189 0.43511275 0.43523740 0.43798107 0.43965873
   [49] 0.44091386 0.44542060 0.44760787 0.44806070 0.45170041 0.45463308
   [55] 0.45701375 0.45742055 0.45884182 0.46026764 0.46079388 0.46462015
   [61] 0.46957464 0.47194125 0.47306775 0.47836431 0.47873180 0.47931354
   [67] 0.48055789 0.48590787 0.49143947 0.49180719 0.52144629 0.52423822
   [73] 0.52590957 0.53223173 0.53321057 0.53458943 0.53629680 0.53719725
   [79] 0.54042624 0.54455214 0.55804631 0.57256072 0.57500289 0.57658517
   [85] 0.57766912 0.57785594 0.58366002 0.58406680 0.58879102 0.59237679
   [91] 0.59397934 0.59436536 0.59879112 0.60556415 0.61032523 0.61812737
   [97] 0.62034707 0.62365185 0.62731643 0.63113137 0.64926511 0.65536232
  [103] 0.65575449 0.66126594 0.68368862 0.70657599 0.70962965 0.71868287
  [109] 0.72362861 0.72384867 0.74617987 0.74690370 0.75629692 0.76448624
  [115] 0.77338741 0.78122041 0.78448374 0.79098573 0.81543698 0.81830741
  [121] 0.81906941 0.82093162 0.82344497 0.83395768 0.83496464 0.83530825
  [127] 0.83571872 0.85664210 0.88448412 0.89078363 0.89319635 0.89381842
  [133] 0.91167761 0.91847387 0.91877486 0.92453621 0.92867231 0.93649656
  [139] 0.95628313 0.96523816 0.96677222 1.01977018 1.02889679 1.03303334
  [145] 1.04683536 1.04918562 1.05960693 1.06576056 1.09102315 1.09935658
  [151] 1.10916465 1.11094999 1.11377045 1.12402021 1.13657027 1.15872851
  [157] 1.15938761 1.17641447 1.19279813 1.20329673 1.20340267 1.20509689
  [163] 1.21079227 1.22192494 1.23240129 1.23498984 1.27193884 1.54297490
  [169] 1.78386136 1.90633993
  Height vectors differ! The maximum relative error is 8.532456e-02.
  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: 759872665.
  
  Execution halted