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: 960665096
  > 
  > 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: 763
  Dissimilarity range: [0,1.3185e-06]
  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: 439
  Dimension: 20
  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: 918
  Dissimilarity range: [0,0.130703]
  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: 56
  Dimension: 20
  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: 137
  Dissimilarity range: [0,408.454]
  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: 937
  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: 466
  Dissimilarity range: [0,3.68916e-09]
  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: 141
  Dimension: 5
  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: 638
  Dissimilarity range: [0,54064.5]
  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: 390
  Dimension: 7
  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: 42
  Dissimilarity range: [0,2.55229e-09]
  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: 714
  Dimension: 20
  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: 783
  Dissimilarity range: [0,0.0334238]
  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: 792
  Dimension: 17
  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: 328
  Dissimilarity range: [0,4.19672e+08]
  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: 251
  Dimension: 7
  Method: single 
      Metric: euclidean 
      Metric: maximum 
      Metric: manhattan 
      Metric: canberra 
    [1] 0.7145438 1.3315922 1.3978348 1.4422950 1.6798554 1.7072862 1.7971338
    [8] 1.7991895 1.8858920 1.8968749 1.8971307 1.9056443 1.9099067 1.9185108
   [15] 1.9551843 1.9909345 1.9940816 2.0342769 2.0436357 2.0489573 2.0769725
   [22] 2.0810907 2.0884503 2.1186689 2.1205884 2.1321456 2.1418280 2.1540877
   [29] 2.1555897 2.1607230 2.1683024 2.1777320 2.1819744 2.1971249 2.2091350
   [36] 2.2151523 2.2159173 2.2180074 2.2257296 2.2406123 2.2419899 2.2499664
   [43] 2.2597838 2.2601025 2.2661285 2.2726773 2.2847597 2.2851621 2.2890230
   [50] 2.2901577 2.2920743 2.2928147 2.2970405 2.2983484 2.3090475 2.3213516
   [57] 2.3418094 2.3435271 2.3476587 2.3478750 2.3571103 2.3682969 2.3686779
   [64] 2.3693780 2.3747246 2.3787720 2.3961948 2.4021327 2.4052436 2.4057542
   [71] 2.4074548 2.4107450 2.4114090 2.4125481 2.4172035 2.4179210 2.4332626
   [78] 2.4374659 2.4382270 2.4417599 2.4418321 2.4462813 2.4471406 2.4533019
   [85] 2.4668388 2.4774258 2.4800508 2.4876456 2.4975190 2.5036062 2.5116858
   [92] 2.5176030 2.5237886 2.5295062 2.5327848 2.5398244 2.5433175 2.5456123
   [99] 2.5458144 2.5545501 2.5621220 2.5639305 2.5744287 2.5763951 2.5766981
  [106] 2.5780044 2.5826007 2.5844688 2.5853827 2.5879370 2.5898142 2.5936980
  [113] 2.5945496 2.5991829 2.5995090 2.6022279 2.6031922 2.6099153 2.6105208
  [120] 2.6239808 2.6246390 2.6259152 2.6270671 2.6279775 2.6294960 2.6303443
  [127] 2.6333782 2.6404729 2.6421240 2.6428187 2.6456395 2.6534034 2.6550758
  [134] 2.6567795 2.6609082 2.6627052 2.6633583 2.6651349 2.6692244 2.6700212
  [141] 2.6718346 2.6766572 2.6777225 2.6817443 2.6835475 2.6845412 2.6853484
  [148] 2.6867447 2.6882745 2.6894152 2.6904153 2.6967384 2.6994637 2.7004561
  [155] 2.7013671 2.7014899 2.7068707 2.7076286 2.7098708 2.7251836 2.7271510
  [162] 2.7286871 2.7345260 2.7353570 2.7444721 2.7457981 2.7463321 2.7486259
  [169] 2.7505414 2.7511452 2.7519580 2.7563928 2.7596029 2.7622508 2.7650197
  [176] 2.7666637 2.7666796 2.7693699 2.7718054 2.7719057 2.7726190 2.7742860
  [183] 2.7803448 2.7870862 2.7946535 2.7971730 2.7977121 2.7983552 2.7991118
  [190] 2.8005808 2.8036962 2.8047054 2.8059542 2.8147101 2.8210601 2.8388779
  [197] 2.8484532 2.8531906 2.8542945 2.8596029 2.8677221 2.8706600 2.8725515
  [204] 2.8786977 2.8813488 2.8842952 2.8954385 2.9005265 2.9011087 2.9019040
  [211] 2.9054548 2.9076251 2.9099282 2.9152785 2.9199089 2.9219773 2.9329168
  [218] 2.9333420 2.9423553 2.9459549 2.9718845 2.9837032 2.9837048 2.9843991
  [225] 2.9845919 2.9982048 3.0099685 3.0158234 3.0179012 3.0414757 3.0446470
  [232] 3.0546860 3.0736657 3.0944187 3.1071961 3.1113131 3.1151480 3.1356847
  [239] 3.1541694 3.1780172 3.1848924 3.2050633 3.2098983 3.2386619 3.2481639
  [246] 3.3193653 3.3692899 3.4434055 3.4890258 3.5536062
    [1] 0.7145438 1.3315922 1.3978348 1.4422950 1.7072862 1.7971338 1.8858920
    [8] 1.8968749 2.0769725 2.0884503 2.0915378 2.1030231 2.1186689 2.1205884
   [15] 2.1321456 2.1418280 2.1540877 2.1683024 2.1736356 2.1777320 2.1819744
   [22] 2.2012207 2.2091350 2.2159173 2.2180074 2.2419899 2.2499664 2.2566377
   [29] 2.2901577 2.2904692 2.2920743 2.2975641 2.2983484 2.3094136 2.3418094
   [36] 2.3571103 2.3686779 2.3931969 2.3955338 2.4081150 2.4090897 2.4172035
   [43] 2.4214990 2.4471406 2.4533019 2.4774258 2.4800508 2.4826834 2.4893022
   [50] 2.4988224 2.5036062 2.5176030 2.5237886 2.5327848 2.5666929 2.5744287
   [57] 2.5853827 2.5975933 2.5976211 2.6031922 2.6171146 2.6259152 2.6333782
   [64] 2.6515725 2.6520863 2.6567795 2.6712085 2.6718346 2.6779013 2.6795253
   [71] 2.6823649 2.6872211 2.6910735 2.6994637 2.7286871 2.7331422 2.7463321
   [78] 2.7486259 2.7529543 2.7596707 2.7613935 2.7634451 2.7650197 2.7666637
   [85] 2.7669496 2.7710508 2.7715868 2.7726190 2.7767006 2.7784931 2.7796211
   [92] 2.7971730 2.7984390 2.8022983 2.8025635 2.8085030 2.8119733 2.8144214
   [99] 2.8147101 2.8232786 2.8251558 2.8281191 2.8320197 2.8360730 2.8388779
  [106] 2.8397696 2.8403719 2.8433715 2.8608368 2.8643322 2.8706600 2.8814697
  [113] 2.8842952 2.8950758 2.8977831 2.9008660 2.9036369 2.9082757 2.9149020
  [120] 2.9166425 2.9448409 2.9459549 2.9469388 2.9502531 2.9515759 2.9523043
  [127] 2.9549563 2.9659997 2.9744838 2.9763270 2.9799161 2.9859256 2.9919910
  [134] 2.9928249 2.9944736 2.9982048 3.0008735 3.0049633 3.0056457 3.0149853
  [141] 3.0186063 3.0217905 3.0264331 3.0304206 3.0338314 3.0340533 3.0381902
  [148] 3.0462119 3.0463370 3.0535871 3.0586062 3.0589532 3.0591647 3.0608299
  [155] 3.0670195 3.0715472 3.0852210 3.0901843 3.0918640 3.1105767 3.1110244
  [162] 3.1131565 3.1182999 3.1207473 3.1225522 3.1267754 3.1325911 3.1326695
  [169] 3.1371230 3.1393179 3.1394784 3.1471924 3.1521163 3.1537765 3.1629901
  [176] 3.1848924 3.2047924 3.2050633 3.2069311 3.2092064 3.2121348 3.2241480
  [183] 3.2243466 3.2280945 3.2349953 3.2386619 3.2481639 3.2483742 3.2513151
  [190] 3.2604537 3.2688405 3.2711837 3.2731653 3.2814227 3.2836959 3.2842108
  [197] 3.2946165 3.3105374 3.3140964 3.3171282 3.3193653 3.3372123 3.3446298
  [204] 3.3473913 3.3538145 3.3676725 3.3692899 3.3817816 3.3844113 3.3877403
  [211] 3.3886019 3.3905742 3.4124047 3.4443998 3.4587387 3.4605136 3.4606828
  [218] 3.4617254 3.4678751 3.4859184 3.4883900 3.4934369 3.4982697 3.5083937
  [225] 3.5164621 3.5239776 3.5359744 3.5395289 3.5689904 3.5885851 3.6011981
  [232] 3.6020534 3.6034905 3.6170209 3.6213230 3.6380485 3.6427817 3.6778531
  [239] 3.6894785 3.7491725 3.7506189 3.7537955 3.7844057 3.7856324 3.8219066
  [246] 3.9533551 4.0657061 4.1836701 4.1907260 4.2219224
  Height vectors differ! The maximum relative error is 1.769414e-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: 960665096.
  
  Execution halted