R version 3.1.2 Patched (2015-01-31 r67684) -- "Pumpkin Helmet" Copyright (C) 2015 The R Foundation for Statistical Computing Platform: x86_64-unknown-linux-gnu (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(cluster) > ## Compare on these: > nms <- c("clustering", "objective", "isolation", "clusinfo", "silinfo") > nm2 <- c("medoids", "id.med", nms) > nm3 <- nm2[- pmatch("obj", nm2)] > > (x <- x0 <- cbind(V1 = (-3:4)^2, V2 = c(0:6,NA), V3 = c(1,2,NA,7,NA,8:9,8))) V1 V2 V3 [1,] 9 0 1 [2,] 4 1 2 [3,] 1 2 NA [4,] 0 3 7 [5,] 1 4 NA [6,] 4 5 8 [7,] 9 6 9 [8,] 16 NA 8 > (px <- pam(x,2, metric="manhattan")) Medoids: ID V1 V2 V3 [1,] 2 4 1 2 [2,] 6 4 5 8 Clustering vector: [1] 1 1 1 2 2 2 2 2 Objective function: build swap 6.375 6.375 Available components: [1] "medoids" "id.med" "clustering" "objective" "isolation" [6] "clusinfo" "silinfo" "diss" "call" "data" > stopifnot(identical(x,x0))# DUP=FALSE .. > pd <- pam(dist(x,"manhattan"), 2) > px2 <- pam(x,2, metric="manhattan", keep.diss=FALSE, keep.data=FALSE) > pdC <- pam(x,2, metric="manhattan", cluster.only = TRUE) > p1 <- pam(x,1, metric="manhattan") > > stopifnot(identical(px[nms], pd[nms]), + identical(px[nms], px2[nms]), + identical(pdC, px2$clustering), + ## and for default dist "euclidean": + identical(pam(x, 2)[nms], + pam(dist(x),2)[nms]), + identical(p1[c("id.med", "objective", "clusinfo")], + list(id.med = 6L, objective = c(build=9.25, swap=9.25), + clusinfo = array(c(8, 18, 9.25, 45, 0), dim = c(1, 5), + dimnames=list(NULL, c("size", "max_diss", "av_diss", + "diameter", "separation"))))), + p1$clustering == 1, is.null(p1$silinfo) + ) > > set.seed(253) > ## generate 250 objects, divided into 2 clusters. > x <- rbind(cbind(rnorm(120, 0,8), rnorm(120, 0,8)), + cbind(rnorm(130,50,8), rnorm(130,10,8))) > > .proctime00 <- proc.time() > > summary(px2 <- pam(x, 2)) Medoids: ID [1,] 61 -0.7697828 -0.2330187 [2,] 163 49.1392167 9.4097259 Clustering vector: [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 [38] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 [75] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 [112] 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 [149] 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 [186] 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 [223] 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 Objective function: build swap 13.25843 10.20817 Numerical information per cluster: size max_diss av_diss diameter separation [1,] 120 31.04843 10.18584 53.22082 9.419035 [2,] 130 26.94337 10.22878 47.86442 9.419035 Isolated clusters: L-clusters: character(0) L*-clusters: character(0) Silhouette plot information: cluster neighbor sil_width 117 1 2 0.80638966 75 1 2 0.80600824 81 1 2 0.80556624 107 1 2 0.80535252 6 1 2 0.80526675 100 1 2 0.80385505 68 1 2 0.80369702 113 1 2 0.80331774 61 1 2 0.80315322 57 1 2 0.80313945 12 1 2 0.80161573 59 1 2 0.80047745 82 1 2 0.79630964 67 1 2 0.79559589 63 1 2 0.79488886 47 1 2 0.79458809 21 1 2 0.79379540 9 1 2 0.79343081 95 1 2 0.79332153 4 1 2 0.79136081 3 1 2 0.79130879 39 1 2 0.79052367 120 1 2 0.78877423 90 1 2 0.78767224 85 1 2 0.78588359 106 1 2 0.78504452 92 1 2 0.78303000 83 1 2 0.78245915 19 1 2 0.78228359 14 1 2 0.78139236 10 1 2 0.77825678 49 1 2 0.77597087 64 1 2 0.77482761 44 1 2 0.77397394 89 1 2 0.77297318 119 1 2 0.77238705 108 1 2 0.77137189 104 1 2 0.76871378 32 1 2 0.76856251 115 1 2 0.76843312 27 1 2 0.76811698 88 1 2 0.76810713 109 1 2 0.76681303 62 1 2 0.76655954 36 1 2 0.76547988 66 1 2 0.76535606 74 1 2 0.76491406 26 1 2 0.76441455 24 1 2 0.76436188 65 1 2 0.76381352 40 1 2 0.76061109 52 1 2 0.75748679 54 1 2 0.75746436 13 1 2 0.75594073 56 1 2 0.75353784 96 1 2 0.75268786 116 1 2 0.75267215 110 1 2 0.75266614 112 1 2 0.75150872 78 1 2 0.75083708 7 1 2 0.74905187 86 1 2 0.74190424 18 1 2 0.74162144 111 1 2 0.74085474 69 1 2 0.74044653 76 1 2 0.73911707 50 1 2 0.73847075 93 1 2 0.73616384 31 1 2 0.73462007 33 1 2 0.73455252 43 1 2 0.73396232 102 1 2 0.72930751 118 1 2 0.72778023 15 1 2 0.72588122 53 1 2 0.72542363 8 1 2 0.72535191 77 1 2 0.72467809 16 1 2 0.72446952 48 1 2 0.72331213 105 1 2 0.72325095 37 1 2 0.72055248 101 1 2 0.71783562 22 1 2 0.71217552 23 1 2 0.71078375 84 1 2 0.70573352 17 1 2 0.70221946 38 1 2 0.69947240 2 1 2 0.69718780 98 1 2 0.69601237 1 1 2 0.69373841 35 1 2 0.69179546 70 1 2 0.69074915 28 1 2 0.68434091 97 1 2 0.68351978 5 1 2 0.67662675 72 1 2 0.67420722 34 1 2 0.67315267 11 1 2 0.67226046 103 1 2 0.67188668 87 1 2 0.67172802 58 1 2 0.67090513 46 1 2 0.66835116 60 1 2 0.66565445 80 1 2 0.65983842 73 1 2 0.65093947 55 1 2 0.64709226 20 1 2 0.64439401 45 1 2 0.63403361 51 1 2 0.63303101 42 1 2 0.62906268 94 1 2 0.60916406 91 1 2 0.59905996 41 1 2 0.57245485 29 1 2 0.55594781 99 1 2 0.55035955 79 1 2 0.50808544 71 1 2 0.46663954 25 1 2 0.43797346 114 1 2 0.16645003 30 1 2 0.08928664 121 2 1 0.80353953 137 2 1 0.80253721 146 2 1 0.80106653 173 2 1 0.80039417 216 2 1 0.79969919 124 2 1 0.79964913 163 2 1 0.79901674 157 2 1 0.79779188 242 2 1 0.79744315 227 2 1 0.79708130 207 2 1 0.79653829 130 2 1 0.79574204 188 2 1 0.79496670 250 2 1 0.79302877 145 2 1 0.79190501 126 2 1 0.79156003 166 2 1 0.79068795 222 2 1 0.78986170 232 2 1 0.78839216 176 2 1 0.78819086 198 2 1 0.78782877 225 2 1 0.78747329 230 2 1 0.78689375 205 2 1 0.78683641 160 2 1 0.78643596 150 2 1 0.78484046 136 2 1 0.78455577 228 2 1 0.78198238 206 2 1 0.78137390 152 2 1 0.78044944 200 2 1 0.77843458 149 2 1 0.77822272 221 2 1 0.77758324 226 2 1 0.77611981 129 2 1 0.77531368 199 2 1 0.77491451 154 2 1 0.77136276 241 2 1 0.77076783 179 2 1 0.77010597 174 2 1 0.76893758 214 2 1 0.76776510 181 2 1 0.76763087 213 2 1 0.76683151 215 2 1 0.76639087 236 2 1 0.76637552 218 2 1 0.76563050 182 2 1 0.76450873 219 2 1 0.76370712 208 2 1 0.76090426 151 2 1 0.75957536 164 2 1 0.75914844 248 2 1 0.75849775 224 2 1 0.75826151 168 2 1 0.75782023 189 2 1 0.75555083 128 2 1 0.75550519 125 2 1 0.75510766 177 2 1 0.75128941 147 2 1 0.75086382 158 2 1 0.75029192 245 2 1 0.74993652 186 2 1 0.74741247 165 2 1 0.74681005 156 2 1 0.74478894 122 2 1 0.74315425 247 2 1 0.74107328 220 2 1 0.74054057 183 2 1 0.73818743 184 2 1 0.73743259 169 2 1 0.73712431 180 2 1 0.73419669 240 2 1 0.73390938 134 2 1 0.73382823 190 2 1 0.73379720 217 2 1 0.73311931 171 2 1 0.73110365 143 2 1 0.72986022 153 2 1 0.72891371 223 2 1 0.72887340 238 2 1 0.72789416 175 2 1 0.72311665 138 2 1 0.72290131 235 2 1 0.72157157 237 2 1 0.71591233 132 2 1 0.71549875 204 2 1 0.71381083 201 2 1 0.71263881 170 2 1 0.70812568 191 2 1 0.70747428 243 2 1 0.70588929 193 2 1 0.70499170 141 2 1 0.70489885 161 2 1 0.70303117 249 2 1 0.69300988 229 2 1 0.69231982 196 2 1 0.69162302 211 2 1 0.69128644 246 2 1 0.68757678 159 2 1 0.68619850 133 2 1 0.68605444 194 2 1 0.68538064 155 2 1 0.68278455 234 2 1 0.68202095 127 2 1 0.68111027 144 2 1 0.67559517 131 2 1 0.65959281 139 2 1 0.65895024 209 2 1 0.65844942 148 2 1 0.65180336 185 2 1 0.64989675 212 2 1 0.63954685 192 2 1 0.63470144 123 2 1 0.63005333 202 2 1 0.61735843 135 2 1 0.61493992 210 2 1 0.60680456 140 2 1 0.58410004 187 2 1 0.58193543 239 2 1 0.57088679 203 2 1 0.56761998 244 2 1 0.55321123 231 2 1 0.55043439 197 2 1 0.52364031 195 2 1 0.51955678 142 2 1 0.47466260 162 2 1 0.46155841 172 2 1 0.45167576 178 2 1 0.42686872 233 2 1 0.37013099 167 2 1 0.32442373 Average silhouette width per cluster: [1] 0.7196104 0.7148520 Average silhouette width of total data set: [1] 0.717136 Available components: [1] "medoids" "id.med" "clustering" "objective" "isolation" [6] "clusinfo" "silinfo" "diss" "call" "data" > pdx <- pam(dist(x), 2) > all.equal(px2[nms], pdx[nms], tol = 1e-12) ## TRUE [1] TRUE > pdxK <- pam(dist(x), 2, keep.diss = TRUE) > stopifnot(identical(pdx[nm2], pdxK[nm2])) > > spdx <- silhouette(pdx) > summary(spdx) Silhouette of 250 units in 2 clusters from pam(x = dist(x), k = 2) : Cluster sizes and average silhouette widths: 120 130 0.7196104 0.7148520 Individual silhouette widths: Min. 1st Qu. Median Mean 3rd Qu. Max. 0.08929 0.69140 0.74400 0.71710 0.77810 0.80640 > spdx cluster neighbor sil_width 117 1 2 0.80638966 75 1 2 0.80600824 81 1 2 0.80556624 107 1 2 0.80535252 6 1 2 0.80526675 100 1 2 0.80385505 68 1 2 0.80369702 113 1 2 0.80331774 61 1 2 0.80315322 57 1 2 0.80313945 12 1 2 0.80161573 59 1 2 0.80047745 82 1 2 0.79630964 67 1 2 0.79559589 63 1 2 0.79488886 47 1 2 0.79458809 21 1 2 0.79379540 9 1 2 0.79343081 95 1 2 0.79332153 4 1 2 0.79136081 3 1 2 0.79130879 39 1 2 0.79052367 120 1 2 0.78877423 90 1 2 0.78767224 85 1 2 0.78588359 106 1 2 0.78504452 92 1 2 0.78303000 83 1 2 0.78245915 19 1 2 0.78228359 14 1 2 0.78139236 10 1 2 0.77825678 49 1 2 0.77597087 64 1 2 0.77482761 44 1 2 0.77397394 89 1 2 0.77297318 119 1 2 0.77238705 108 1 2 0.77137189 104 1 2 0.76871378 32 1 2 0.76856251 115 1 2 0.76843312 27 1 2 0.76811698 88 1 2 0.76810713 109 1 2 0.76681303 62 1 2 0.76655954 36 1 2 0.76547988 66 1 2 0.76535606 74 1 2 0.76491406 26 1 2 0.76441455 24 1 2 0.76436188 65 1 2 0.76381352 40 1 2 0.76061109 52 1 2 0.75748679 54 1 2 0.75746436 13 1 2 0.75594073 56 1 2 0.75353784 96 1 2 0.75268786 116 1 2 0.75267215 110 1 2 0.75266614 112 1 2 0.75150872 78 1 2 0.75083708 7 1 2 0.74905187 86 1 2 0.74190424 18 1 2 0.74162144 111 1 2 0.74085474 69 1 2 0.74044653 76 1 2 0.73911707 50 1 2 0.73847075 93 1 2 0.73616384 31 1 2 0.73462007 33 1 2 0.73455252 43 1 2 0.73396232 102 1 2 0.72930751 118 1 2 0.72778023 15 1 2 0.72588122 53 1 2 0.72542363 8 1 2 0.72535191 77 1 2 0.72467809 16 1 2 0.72446952 48 1 2 0.72331213 105 1 2 0.72325095 37 1 2 0.72055248 101 1 2 0.71783562 22 1 2 0.71217552 23 1 2 0.71078375 84 1 2 0.70573352 17 1 2 0.70221946 38 1 2 0.69947240 2 1 2 0.69718780 98 1 2 0.69601237 1 1 2 0.69373841 35 1 2 0.69179546 70 1 2 0.69074915 28 1 2 0.68434091 97 1 2 0.68351978 5 1 2 0.67662675 72 1 2 0.67420722 34 1 2 0.67315267 11 1 2 0.67226046 103 1 2 0.67188668 87 1 2 0.67172802 58 1 2 0.67090513 46 1 2 0.66835116 60 1 2 0.66565445 80 1 2 0.65983842 73 1 2 0.65093947 55 1 2 0.64709226 20 1 2 0.64439401 45 1 2 0.63403361 51 1 2 0.63303101 42 1 2 0.62906268 94 1 2 0.60916406 91 1 2 0.59905996 41 1 2 0.57245485 29 1 2 0.55594781 99 1 2 0.55035955 79 1 2 0.50808544 71 1 2 0.46663954 25 1 2 0.43797346 114 1 2 0.16645003 30 1 2 0.08928664 121 2 1 0.80353953 137 2 1 0.80253721 146 2 1 0.80106653 173 2 1 0.80039417 216 2 1 0.79969919 124 2 1 0.79964913 163 2 1 0.79901674 157 2 1 0.79779188 242 2 1 0.79744315 227 2 1 0.79708130 207 2 1 0.79653829 130 2 1 0.79574204 188 2 1 0.79496670 250 2 1 0.79302877 145 2 1 0.79190501 126 2 1 0.79156003 166 2 1 0.79068795 222 2 1 0.78986170 232 2 1 0.78839216 176 2 1 0.78819086 198 2 1 0.78782877 225 2 1 0.78747329 230 2 1 0.78689375 205 2 1 0.78683641 160 2 1 0.78643596 150 2 1 0.78484046 136 2 1 0.78455577 228 2 1 0.78198238 206 2 1 0.78137390 152 2 1 0.78044944 200 2 1 0.77843458 149 2 1 0.77822272 221 2 1 0.77758324 226 2 1 0.77611981 129 2 1 0.77531368 199 2 1 0.77491451 154 2 1 0.77136276 241 2 1 0.77076783 179 2 1 0.77010597 174 2 1 0.76893758 214 2 1 0.76776510 181 2 1 0.76763087 213 2 1 0.76683151 215 2 1 0.76639087 236 2 1 0.76637552 218 2 1 0.76563050 182 2 1 0.76450873 219 2 1 0.76370712 208 2 1 0.76090426 151 2 1 0.75957536 164 2 1 0.75914844 248 2 1 0.75849775 224 2 1 0.75826151 168 2 1 0.75782023 189 2 1 0.75555083 128 2 1 0.75550519 125 2 1 0.75510766 177 2 1 0.75128941 147 2 1 0.75086382 158 2 1 0.75029192 245 2 1 0.74993652 186 2 1 0.74741247 165 2 1 0.74681005 156 2 1 0.74478894 122 2 1 0.74315425 247 2 1 0.74107328 220 2 1 0.74054057 183 2 1 0.73818743 184 2 1 0.73743259 169 2 1 0.73712431 180 2 1 0.73419669 240 2 1 0.73390938 134 2 1 0.73382823 190 2 1 0.73379720 217 2 1 0.73311931 171 2 1 0.73110365 143 2 1 0.72986022 153 2 1 0.72891371 223 2 1 0.72887340 238 2 1 0.72789416 175 2 1 0.72311665 138 2 1 0.72290131 235 2 1 0.72157157 237 2 1 0.71591233 132 2 1 0.71549875 204 2 1 0.71381083 201 2 1 0.71263881 170 2 1 0.70812568 191 2 1 0.70747428 243 2 1 0.70588929 193 2 1 0.70499170 141 2 1 0.70489885 161 2 1 0.70303117 249 2 1 0.69300988 229 2 1 0.69231982 196 2 1 0.69162302 211 2 1 0.69128644 246 2 1 0.68757678 159 2 1 0.68619850 133 2 1 0.68605444 194 2 1 0.68538064 155 2 1 0.68278455 234 2 1 0.68202095 127 2 1 0.68111027 144 2 1 0.67559517 131 2 1 0.65959281 139 2 1 0.65895024 209 2 1 0.65844942 148 2 1 0.65180336 185 2 1 0.64989675 212 2 1 0.63954685 192 2 1 0.63470144 123 2 1 0.63005333 202 2 1 0.61735843 135 2 1 0.61493992 210 2 1 0.60680456 140 2 1 0.58410004 187 2 1 0.58193543 239 2 1 0.57088679 203 2 1 0.56761998 244 2 1 0.55321123 231 2 1 0.55043439 197 2 1 0.52364031 195 2 1 0.51955678 142 2 1 0.47466260 162 2 1 0.46155841 172 2 1 0.45167576 178 2 1 0.42686872 233 2 1 0.37013099 167 2 1 0.32442373 attr(,"Ordered") [1] TRUE attr(,"call") pam(x = dist(x), k = 2) attr(,"class") [1] "silhouette" > postscript("pam-tst.ps") > if(FALSE) + plot(spdx)# the silhouette > ## is now identical : > plot(pdx)# failed in 1.7.0 -- now only does silhouette > > par(mfrow = 2:1) > ## new 'dist' argument for clusplot(): > plot(pdx, dist=dist(x)) > ## but this should work automagically (via eval()) as well: > plot(pdx) > ## or this > clusplot(pdx) > > data(ruspini) > summary(pr4 <- pam(ruspini, 4)) Medoids: ID x y 10 10 19 65 32 32 44 149 52 52 99 119 70 70 69 21 Clustering vector: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 Objective function: build swap 17.22898 11.48637 Numerical information per cluster: size max_diss av_diss diameter separation [1,] 20 24.04163 12.55362 40.24922 40.49691 [2,] 23 26.92582 10.44238 36.61967 24.04163 [3,] 17 33.97058 13.84800 47.63402 24.04163 [4,] 15 17.02939 8.98767 27.07397 40.49691 Isolated clusters: L-clusters: character(0) L*-clusters: [1] 1 4 Silhouette plot information: cluster neighbor sil_width 10 1 4 0.8056096 6 1 4 0.7954977 9 1 4 0.7923048 11 1 4 0.7831672 8 1 2 0.7811793 12 1 4 0.7658171 3 1 4 0.7587961 14 1 4 0.7569107 2 1 4 0.7456150 16 1 4 0.7436018 13 1 4 0.7398841 4 1 2 0.7361533 18 1 4 0.7080079 15 1 4 0.7006854 19 1 4 0.7000938 1 1 4 0.6798381 5 1 4 0.6646571 20 1 4 0.6619626 17 1 4 0.6148541 7 1 2 0.5900575 26 2 3 0.8357433 32 2 3 0.8332753 27 2 3 0.8290271 25 2 3 0.8285547 28 2 3 0.8192636 35 2 3 0.8186309 33 2 3 0.8175087 23 2 3 0.8089969 22 2 3 0.8025389 34 2 3 0.8013310 31 2 3 0.7949677 36 2 3 0.7943536 24 2 3 0.7930770 29 2 3 0.7897346 30 2 3 0.7892027 21 2 3 0.7698024 37 2 3 0.7684502 39 2 3 0.7631648 38 2 3 0.7438848 40 2 3 0.7083130 42 2 3 0.5291270 43 2 3 0.4931623 41 2 3 0.4290814 54 3 2 0.7741745 57 3 2 0.7703455 55 3 2 0.7641810 50 3 2 0.7619943 52 3 2 0.7616220 56 3 2 0.7575313 59 3 2 0.7327828 49 3 2 0.7317002 51 3 2 0.7209864 60 3 2 0.7206840 58 3 2 0.7019611 53 3 2 0.6775322 45 3 2 0.5974787 46 3 2 0.5740823 47 3 2 0.4835635 48 3 2 0.4247331 44 3 2 0.4196093 70 4 1 0.8548947 67 4 1 0.8527439 65 4 1 0.8503105 69 4 1 0.8391810 71 4 1 0.8381065 66 4 1 0.8229841 62 4 1 0.8153092 64 4 1 0.8061254 73 4 1 0.7950213 63 4 1 0.7795369 72 4 1 0.7748121 61 4 1 0.7701103 68 4 1 0.7620559 74 4 1 0.7596815 75 4 1 0.7425538 Average silhouette width per cluster: [1] 0.7262347 0.7548344 0.6691154 0.8042285 Average silhouette width of total data set: [1] 0.737657 2775 dissimilarities, summarized : Min. 1st Qu. Median Mean 3rd Qu. Max. 1.4142 40.1060 75.5910 71.5380 99.1690 154.5000 Metric : euclidean Number of objects : 75 Available components: [1] "medoids" "id.med" "clustering" "objective" "isolation" [6] "clusinfo" "silinfo" "diss" "call" "data" > (pr3 <- pam(ruspini, 3)) Medoids: ID x y 17 17 30 52 32 32 44 149 52 52 99 119 Clustering vector: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Objective function: build swap 25.68229 21.59293 Available components: [1] "medoids" "id.med" "clustering" "objective" "isolation" [6] "clusinfo" "silinfo" "diss" "call" "data" > (pr5 <- pam(ruspini, 5)) Medoids: ID x y 10 10 19 65 32 32 44 149 52 52 99 119 47 47 78 94 70 70 69 21 Clustering vector: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 4 4 4 3 3 3 3 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 3 3 3 3 3 3 3 3 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 Objective function: build swap 12.09864 10.39579 Available components: [1] "medoids" "id.med" "clustering" "objective" "isolation" [6] "clusinfo" "silinfo" "diss" "call" "data" > > data(votes.repub) > summary(pv3 <- pam(votes.repub, 3)) Medoids: ID X1856 X1860 X1864 X1868 X1872 X1876 X1880 X1884 X1888 X1892 X1896 Alabama 1 NA NA NA 51.44 53.19 40.02 36.98 38.44 32.28 3.95 28.13 Alaska 2 NA NA NA NA NA NA NA NA NA NA NA New Mexico 31 NA NA NA NA NA NA NA NA NA NA NA X1900 X1904 X1908 X1912 X1916 X1920 X1924 X1928 X1932 X1936 X1940 Alabama 34.67 20.65 24.38 8.26 21.97 30.98 27.01 48.49 14.15 12.82 14.34 Alaska NA NA NA NA NA NA NA NA NA NA NA New Mexico NA NA NA 35.91 46.53 54.68 48.52 59.01 35.76 36.50 43.28 X1944 X1948 X1952 X1956 X1960 X1964 X1968 X1972 X1976 Alabama 18.20 19.04 35.02 39.39 41.75 69.5 14.0 72.4 43.48 Alaska NA NA NA NA 50.94 34.1 45.3 58.1 62.91 New Mexico 46.44 42.93 55.39 57.81 49.41 41.0 51.8 61.0 51.04 Clustering vector: Alabama Alaska Arizona Arkansas California 1 2 3 1 2 Colorado Connecticut Delaware Florida Georgia 2 2 3 1 1 Hawaii Idaho Illinois Indiana Iowa 2 3 2 3 3 Kansas Kentucky Louisiana Maine Maryland 2 3 1 2 3 Massachusetts Michigan Minnesota Mississippi Missouri 3 2 3 1 3 Montana Nebraska Nevada New Hampshire New Jersey 3 3 2 2 2 New Mexico New York North Carolina North Dakota Ohio 3 3 3 2 3 Oklahoma Oregon Pennsylvania Rhode Island South Carolina 3 3 2 3 2 South Dakota Tennessee Texas Utah Vermont 3 3 2 3 2 Virginia Washington West Virginia Wisconsin Wyoming 2 3 3 3 3 Objective function: build swap 38.32548 38.32548 Numerical information per cluster: size max_diss av_diss diameter separation [1,] 6 78.92731 51.59134 116.7048 50.14189 [2,] 18 86.54675 38.47068 271.2455 19.42184 [3,] 26 60.03879 35.16361 124.8324 19.42184 Isolated clusters: L-clusters: character(0) L*-clusters: character(0) Silhouette plot information: cluster neighbor sil_width Louisiana 1 3 0.54689535 Alabama 1 3 0.52839272 Georgia 1 3 0.52730253 Mississippi 1 2 0.52454810 Florida 1 3 0.25211631 Arkansas 1 3 0.24131701 Alaska 2 3 0.15699268 Hawaii 2 3 0.08479842 Vermont 2 3 -0.02620975 Maine 2 3 -0.03284950 Michigan 2 3 -0.11524982 Pennsylvania 2 3 -0.15341477 New Hampshire 2 3 -0.17099889 Connecticut 2 3 -0.19095000 New Jersey 2 3 -0.19281567 Kansas 2 3 -0.19719316 California 2 3 -0.24006293 Illinois 2 3 -0.25236336 North Dakota 2 3 -0.25464430 Virginia 2 3 -0.26262534 Nevada 2 3 -0.27016336 Colorado 2 3 -0.27885043 Texas 2 1 -0.47297583 South Carolina 2 1 -0.50899710 New Mexico 3 2 0.39555584 Washington 3 2 0.32989454 Oklahoma 3 2 0.30953823 Wyoming 3 2 0.30163169 Idaho 3 2 0.29915132 Montana 3 2 0.29105494 Missouri 3 2 0.29038462 Oregon 3 2 0.27710695 Maryland 3 2 0.27437520 West Virginia 3 2 0.27089938 Utah 3 2 0.26964380 Tennessee 3 2 0.26846440 Arizona 3 2 0.25968564 Delaware 3 2 0.25920434 Kentucky 3 2 0.25868341 South Dakota 3 2 0.25615670 Indiana 3 2 0.25031548 Wisconsin 3 2 0.21808013 Ohio 3 2 0.21477474 Nebraska 3 2 0.20965953 North Carolina 3 2 0.19201537 Minnesota 3 2 0.18955165 New York 3 2 0.18820394 Iowa 3 2 0.17296046 Rhode Island 3 2 0.12599915 Massachusetts 3 2 0.12106770 Average silhouette width per cluster: [1] 0.4367620 -0.1876985 0.2497715 Average silhouette width of total data set: [1] 0.1147212 1225 dissimilarities, summarized : Min. 1st Qu. Median Mean 3rd Qu. Max. 17.199 48.343 64.681 82.227 105.490 281.950 Metric : euclidean Number of objects : 50 Available components: [1] "medoids" "id.med" "clustering" "objective" "isolation" [6] "clusinfo" "silinfo" "diss" "call" "data" > (pv4 <- pam(votes.repub, 4)) Medoids: ID X1856 X1860 X1864 X1868 X1872 X1876 X1880 X1884 X1888 X1892 X1896 Alabama 1 NA NA NA 51.44 53.19 40.02 36.98 38.44 32.28 3.95 28.13 Alaska 2 NA NA NA NA NA NA NA NA NA NA NA New Mexico 31 NA NA NA NA NA NA NA NA NA NA NA Iowa 15 49.13 54.87 64.23 61.92 64.18 58.58 56.85 52.42 52.36 49.60 55.46 X1900 X1904 X1908 X1912 X1916 X1920 X1924 X1928 X1932 X1936 X1940 Alabama 34.67 20.65 24.38 8.26 21.97 30.98 27.01 48.49 14.15 12.82 14.34 Alaska NA NA NA NA NA NA NA NA NA NA NA New Mexico NA NA NA 35.91 46.53 54.68 48.52 59.01 35.76 36.50 43.28 Iowa 57.99 63.37 55.62 24.30 54.06 70.91 55.06 61.80 39.98 42.70 52.03 X1944 X1948 X1952 X1956 X1960 X1964 X1968 X1972 X1976 Alabama 18.20 19.04 35.02 39.39 41.75 69.5 14.0 72.4 43.48 Alaska NA NA NA NA 50.94 34.1 45.3 58.1 62.91 New Mexico 46.44 42.93 55.39 57.81 49.41 41.0 51.8 61.0 51.04 Iowa 51.99 47.58 63.76 59.06 56.71 38.1 53.0 57.6 50.51 Clustering vector: Alabama Alaska Arizona Arkansas California 1 2 3 1 2 Colorado Connecticut Delaware Florida Georgia 2 2 3 1 1 Hawaii Idaho Illinois Indiana Iowa 2 3 4 3 4 Kansas Kentucky Louisiana Maine Maryland 4 3 1 2 3 Massachusetts Michigan Minnesota Mississippi Missouri 4 2 4 1 3 Montana Nebraska Nevada New Hampshire New Jersey 3 4 2 2 2 New Mexico New York North Carolina North Dakota Ohio 3 3 3 4 4 Oklahoma Oregon Pennsylvania Rhode Island South Carolina 3 3 4 4 2 South Dakota Tennessee Texas Utah Vermont 4 3 2 3 2 Virginia Washington West Virginia Wisconsin Wyoming 2 3 3 4 3 Objective function: build swap 35.84182 35.84182 Available components: [1] "medoids" "id.med" "clustering" "objective" "isolation" [6] "clusinfo" "silinfo" "diss" "call" "data" > (pv6 <- pam(votes.repub, 6, trace = 3)) C pam(): computing 1226 dissimilarities from 50 x 31 matrix: [Ok] pam()'s bswap(*, s=281.951, pamonce=0): build 6 medoids: new repr. 2 new repr. 1 new repr. 31 new repr. 15 new repr. 46 new repr. 40 after build: medoids are 1 2 15 31 40 46 and min.dist dysma[1:n] are 0 0 37.7 56 35.8 28.5 28.6 31.7 54.1 48.2 51.7 33.2 27.3 30.5 0 35.1 25.4 60.9 36.9 26.7 48.4 28.1 33.2 63.1 21.1 28.6 37.5 35.8 29.8 31.3 0 32 29.9 35.7 30.9 35.1 27.8 35.7 50.2 0 26.2 30.2 45.2 34.1 33.8 0 28.5 35.1 34.2 28.8 swp new 10 <-> 1 old; decreasing diss. 1579.03 by -2.57067 end{bswap()}, end{cstat()} Medoids: ID X1856 X1860 X1864 X1868 X1872 X1876 X1880 X1884 X1888 X1892 Georgia 10 NA NA NA 35.72 43.77 27.94 34.33 33.84 28.33 21.80 Alaska 2 NA NA NA NA NA NA NA NA NA NA Virginia 46 0.19 1.15 NA NA 50.48 40.62 39.52 48.90 49.47 38.75 New Mexico 31 NA NA NA NA NA NA NA NA NA NA Iowa 15 49.13 54.87 64.23 61.92 64.18 58.58 56.85 52.42 52.36 49.60 South Carolina 40 NA NA NA 57.93 75.95 50.26 33.97 23.72 17.27 18.99 X1896 X1900 X1904 X1908 X1912 X1916 X1920 X1924 X1928 X1932 Georgia 36.82 28.56 18.32 31.40 4.27 7.07 28.57 18.19 43.37 7.77 Alaska NA NA NA NA NA NA NA NA NA NA Virginia 45.90 43.81 36.67 38.36 17.00 32.05 37.85 32.79 53.91 30.09 New Mexico NA NA NA NA 35.91 46.53 54.68 48.52 59.01 35.76 Iowa 55.46 57.99 63.37 55.62 24.30 54.06 70.91 55.06 61.80 39.98 South Carolina 13.51 7.04 4.63 5.97 1.06 2.43 3.90 2.21 8.54 1.89 X1936 X1940 X1944 X1948 X1952 X1956 X1960 X1964 X1968 X1972 Georgia 12.60 14.84 18.25 18.31 30.34 33.22 37.44 54.1 30.4 75.0 Alaska NA NA NA NA NA NA 50.94 34.1 45.3 58.1 Virginia 29.39 31.55 37.39 41.04 56.32 55.37 52.44 46.5 41.4 67.8 New Mexico 36.50 43.28 46.44 42.93 55.39 57.81 49.41 41.0 51.8 61.0 Iowa 42.70 52.03 51.99 47.58 63.76 59.06 56.71 38.1 53.0 57.6 South Carolina 1.43 4.37 4.46 3.78 49.28 25.18 48.76 58.9 38.1 70.8 X1976 Georgia 33.02 Alaska 62.91 Virginia 50.73 New Mexico 51.04 Iowa 50.51 South Carolina 43.54 Clustering vector: Alabama Alaska Arizona Arkansas California 1 2 3 3 2 Colorado Connecticut Delaware Florida Georgia 2 2 4 3 1 Hawaii Idaho Illinois Indiana Iowa 2 4 5 4 5 Kansas Kentucky Louisiana Maine Maryland 5 4 1 2 4 Massachusetts Michigan Minnesota Mississippi Missouri 5 2 5 6 4 Montana Nebraska Nevada New Hampshire New Jersey 4 5 2 2 2 New Mexico New York North Carolina North Dakota Ohio 4 4 3 5 5 Oklahoma Oregon Pennsylvania Rhode Island South Carolina 4 4 5 5 6 South Dakota Tennessee Texas Utah Vermont 5 3 2 4 2 Virginia Washington West Virginia Wisconsin Wyoming 3 4 4 5 4 Objective function: build swap 31.58067 31.52926 Available components: [1] "medoids" "id.med" "clustering" "objective" "isolation" [6] "clusinfo" "silinfo" "diss" "call" "data" > > cat('Time elapsed: ', proc.time() - .proctime00,'\n') Time elapsed: 1.817 0.028 1.938 0 0 > > ## re-starting with medoids from pv6 shouldn't change: > pv6. <- pam(votes.repub, 6, medoids = pv6$id.med, trace = 3) C pam(): computing 1226 dissimilarities from 50 x 31 matrix: [Ok] pam()'s bswap(*, s=281.951, pamonce=0): medoids given after build: medoids are 2 10 15 31 40 46 and min.dist dysma[1:n] are 48.2 0 37.7 56 35.8 28.5 28.6 31.7 54.1 0 51.7 33.2 27.3 30.5 0 35.1 25.4 58.3 36.9 26.7 48.4 28.1 33.2 63.1 21.1 28.6 37.5 35.8 29.8 31.3 0 32 29.9 35.7 30.9 35.1 27.8 35.7 50.2 0 26.2 30.2 45.2 34.1 33.8 0 28.5 35.1 34.2 28.8 end{bswap()}, end{cstat()} > identical(pv6[nm3], pv6.[nm3]) [1] TRUE > > ## This example seg.faulted at some point: > d.st <- data.frame(V1= c(9, 12, 12, 15, 9, 9, 13, 11, 15, 10, 13, 13, + 13, 15, 8, 13, 13, 10, 7, 9, 6, 11, 3), + V2= c(5, 9, 3, 5, 1, 1, 2, NA, 10, 1, 4, 7, + 4, NA, NA, 5, 2, 4, 3, 3, 6, 1, 1), + V3 = c(63, 41, 59, 50, 290, 226, 60, 36, 32, 121, 70, 51, + 79, 32, 42, 39, 76, 60, 56, 88, 57, 309, 254), + V4 = c(146, 43, 78, 88, 314, 149, 78, NA, 238, 153, 159, 222, + 203, NA, NA, 74, 100, 111, 9, 180, 50, 256, 107)) > dd <- daisy(d.st, stand = TRUE) > (r0 <- pam(dd, 5))# cluster 5 = { 23 } -- on single observation Medoids: ID [1,] 15 15 [2,] 8 8 [3,] 14 14 [4,] 22 22 [5,] 23 23 Clustering vector: [1] 1 2 2 3 4 4 2 2 3 2 2 2 2 3 1 2 2 2 1 1 1 4 5 Objective function: build swap 0.9368049 0.8621860 Available components: [1] "medoids" "id.med" "clustering" "objective" "isolation" [6] "clusinfo" "silinfo" "diss" "call" > ## pam doing the "daisy" computation internally: > r0s <- pam(d.st, 5, stand=TRUE, keep.diss=FALSE, keep.data=FALSE) > (ii <- which(names(r0) %in% c("call","medoids"))) [1] 1 9 > stopifnot(all.equal(r0[-ii], r0s[-ii], tol=1e-14), + identical(r0s$medoids, data.matrix(d.st)[r0$medoids, ])) > > ## This gave only 3 different medoids -> and seg.fault: > (r5 <- pam(dd, 5, medoids = c(1,3,20,2,5), trace = 2)) # now "fine" pam()'s bswap(*, s=8.51931, pamonce=0): medoids given after build: medoids are 1 2 3 5 20 swp new 14 <-> 2 old; decreasing diss. 29.8745 by -5.50096 swp new 15 <-> 1 old; decreasing diss. 24.3735 by -2.20162 swp new 6 <-> 20 old; decreasing diss. 22.1719 by -2.12745 swp new 8 <-> 3 old; decreasing diss. 20.0444 by -0.201608 end{bswap()}, end{cstat()} Medoids: ID [1,] 15 15 [2,] 8 8 [3,] 14 14 [4,] 5 5 [5,] 6 6 Clustering vector: [1] 1 2 2 3 4 5 2 2 3 5 2 2 2 3 1 2 2 2 1 1 1 4 5 Objective function: build swap 1.2988899 0.8627319 Available components: [1] "medoids" "id.med" "clustering" "objective" "isolation" [6] "clusinfo" "silinfo" "diss" "call" > > dev.off() null device 1 > > ##------------------------ Testing pam() with new "pamonce" argument: > > ## This is from "next version of Matrix" test-tools-1.R: > showSys.time <- function(expr) { + ## prepend 'Time' for R CMD Rdiff + st <- system.time(expr) + writeLines(paste("Time", capture.output(print(st)))) + invisible(st) + } > show2Ratios <- function(...) { + stopifnot(length(rgs <- list(...)) == 2, + nchar(ns <- names(rgs)) > 0) + r <- round(cbind(..1, ..2)[c(1,3),], 3) + dimnames(r) <- list(paste("Time ", rownames(r)), ns) + r + } > > > n <- 1000 > ## If not enough cases, all CPU times equals 0. > n <- 500 # for now, and automatic testing > > sd <- 0.5 > set.seed(13) > n2 <- as.integer(round(n * 1.5)) > x <- rbind(cbind(rnorm( n,0,sd), rnorm( n,0,sd)), + cbind(rnorm(n2,5,sd), rnorm(n2,5,sd)), + cbind(rnorm(n2,7,sd), rnorm(n2,7,sd)), + cbind(rnorm(n2,9,sd), rnorm(n2,9,sd))) > > > ## original algorithm > st0 <- showSys.time(pamx <- pam(x, 4, trace.lev=2))# 8.157 0.024 8.233 C pam(): computing 3779876 dissimilarities from 2750 x 2 matrix: [Ok] pam()'s bswap(*, s=15.7788, pamonce=0): build 4 medoids: new repr. 1268 new repr. 414 new repr. 2153 new repr. 915 after build: medoids are 414 915 1268 2153 swp new 1793 <-> 1268 old; decreasing diss. 1862.37 by -129.13 end{bswap()}, end{cstat()} Time user system elapsed Time 1.832 0.032 1.893 > ## bswapPamOnce algorithm > st1 <- showSys.time(pamxonce <- pam(x, 4, pamonce=TRUE, trace.lev=2))# 6.122 0.024 6.181 C pam(): computing 3779876 dissimilarities from 2750 x 2 matrix: [Ok] pam()'s bswap(*, s=15.7788, pamonce=1): build 4 medoids: new repr. 1268 new repr. 414 new repr. 2153 new repr. 915 after build: medoids are 414 915 1268 2153 swp new 1793 <-> 1268 old; decreasing diss. 1862.37 by -129.13 end{bswap()}, end{cstat()} Time user system elapsed Time 1.607 0.024 1.639 > ## bswapPamOnceDistIndice > st2 <- showSys.time(pamxonce2 <- pam(x, 4, pamonce = 2, trace.lev=2))# 4.101 0.024 4.151 C pam(): computing 3779876 dissimilarities from 2750 x 2 matrix: [Ok] pam()'s bswap(*, s=15.7788, pamonce=2): build 4 medoids: new repr. 1268 new repr. 414 new repr. 2153 new repr. 915 after build: medoids are 414 915 1268 2153 swp new 1793 <-> 1268 old; decreasing diss. 1862.37 by -129.13 end{bswap()}, end{cstat()} Time user system elapsed Time 1.302 0.000 1.304 > show2Ratios('2:orig' = st2/st0, '1:orig' = st1/st0) 2:orig 1:orig Time user.self 0.711 0.877 Time elapsed 0.689 0.866 > > ## only call element is not equal > (icall <- which(names(pamx) == "call")) [1] 9 > pamx[[icall]] pam(x = x, k = 4, trace.lev = 2) > stopifnot(all.equal(pamx [-icall], pamxonce [-icall]), + all.equal(pamxonce[-icall], pamxonce2[-icall])) > > ## Same using specified medoids > (med0 <- 1 + round(n* c(0,1, 2.5, 4)))# lynne (~ 2010, AMD Phenom II X4 925) [1] 1 501 1251 2001 > st0 <- showSys.time(pamxst <- pam(x, 4, medoids = med0, trace.lev=2))# 13.071 0.024 13.177 C pam(): computing 3779876 dissimilarities from 2750 x 2 matrix: [Ok] pam()'s bswap(*, s=15.7788, pamonce=0): medoids given after build: medoids are 1 501 1251 2001 swp new 915 <-> 501 old; decreasing diss. 2126.83 by -197.507 swp new 1793 <-> 1251 old; decreasing diss. 1929.32 by -101.336 swp new 414 <-> 1 old; decreasing diss. 1827.98 by -86.3404 swp new 2153 <-> 2001 old; decreasing diss. 1741.64 by -8.40201 end{bswap()}, end{cstat()} Time user system elapsed Time 2.574 0.004 2.579 > st1 <- showSys.time(pamxoncest <- pam(x, 4, medoids = med0, pamonce=TRUE, trace.lev=2))# 8.503 0.024 8.578 C pam(): computing 3779876 dissimilarities from 2750 x 2 matrix: [Ok] pam()'s bswap(*, s=15.7788, pamonce=1): medoids given after build: medoids are 1 501 1251 2001 swp new 915 <-> 501 old; decreasing diss. 2126.83 by -197.507 swp new 1793 <-> 1251 old; decreasing diss. 1929.32 by -101.336 swp new 414 <-> 1 old; decreasing diss. 1827.98 by -86.3404 swp new 2153 <-> 2001 old; decreasing diss. 1741.64 by -8.40201 end{bswap()}, end{cstat()} Time user system elapsed Time 2.121 0.000 2.129 > st2 <- showSys.time(pamxonce2st <- pam(x, 4, medoids = med0, pamonce=2, trace.lev=2))# 5.587 0.025 5.647 C pam(): computing 3779876 dissimilarities from 2750 x 2 matrix: [Ok] pam()'s bswap(*, s=15.7788, pamonce=2): medoids given after build: medoids are 1 501 1251 2001 swp new 915 <-> 501 old; decreasing diss. 2126.83 by -197.507 swp new 1793 <-> 1251 old; decreasing diss. 1929.32 by -101.336 swp new 414 <-> 1 old; decreasing diss. 1827.98 by -86.3404 swp new 2153 <-> 2001 old; decreasing diss. 1741.64 by -8.40201 end{bswap()}, end{cstat()} Time user system elapsed Time 1.305 0.004 1.310 > show2Ratios('2:orig' = st2/st0, '1:orig' = st1/st0) 2:orig 1:orig Time user.self 0.507 0.824 Time elapsed 0.508 0.826 > > ## only call element is not equal > stopifnot(all.equal(pamxst [-icall], pamxoncest [-icall]), + all.equal(pamxoncest[-icall], pamxonce2st[-icall])) > > ## Different starting values > med0 <- 1:4 # lynne (~ 2010, AMD Phenom II X4 925) > st0 <- showSys.time(pamxst <- pam(x, 4, medoids = med0, trace.lev=2))# 13.416 0.023 13.529 C pam(): computing 3779876 dissimilarities from 2750 x 2 matrix: [Ok] pam()'s bswap(*, s=15.7788, pamonce=0): medoids given after build: medoids are 1 2 3 4 swp new 1421 <-> 4 old; decreasing diss. 21009.4 by -15939.9 swp new 2153 <-> 3 old; decreasing diss. 5069.52 by -1657.88 swp new 915 <-> 2 old; decreasing diss. 3411.65 by -1592.06 swp new 414 <-> 1 old; decreasing diss. 1819.59 by -86.3404 swp new 1793 <-> 1421 old; decreasing diss. 1733.25 by -0.00639415 end{bswap()}, end{cstat()} Time user system elapsed Time 3.087 0.000 3.087 > st1 <- showSys.time(pamxoncest <- pam(x, 4, medoids = med0, pamonce=TRUE, trace.lev=2))# 8.384 0.024 8.459 C pam(): computing 3779876 dissimilarities from 2750 x 2 matrix: [Ok] pam()'s bswap(*, s=15.7788, pamonce=1): medoids given after build: medoids are 1 2 3 4 swp new 1421 <-> 4 old; decreasing diss. 21009.4 by -15939.9 swp new 2153 <-> 3 old; decreasing diss. 5069.52 by -1657.88 swp new 915 <-> 2 old; decreasing diss. 3411.65 by -1592.06 swp new 414 <-> 1 old; decreasing diss. 1819.59 by -86.3404 swp new 1793 <-> 1421 old; decreasing diss. 1733.25 by -0.00639415 end{bswap()}, end{cstat()} Time user system elapsed Time 2.487 0.000 2.488 > st2 <- showSys.time(pamxonce2st <- pam(x, 4, medoids = med0, pamonce=2, trace.lev=2))# 5.455 0.030 5.520 C pam(): computing 3779876 dissimilarities from 2750 x 2 matrix: [Ok] pam()'s bswap(*, s=15.7788, pamonce=2): medoids given after build: medoids are 1 2 3 4 swp new 1421 <-> 4 old; decreasing diss. 21009.4 by -15939.9 swp new 2153 <-> 3 old; decreasing diss. 5069.52 by -1657.88 swp new 915 <-> 2 old; decreasing diss. 3411.65 by -1592.06 swp new 414 <-> 1 old; decreasing diss. 1819.59 by -86.3404 swp new 1793 <-> 1421 old; decreasing diss. 1733.25 by -0.00639415 end{bswap()}, end{cstat()} Time user system elapsed Time 1.566 0.000 1.568 > show2Ratios('2:orig' = st2/st0, '1:orig' = st1/st0) 2:orig 1:orig Time user.self 0.507 0.806 Time elapsed 0.508 0.806 > > ## only call element is not equal > stopifnot(all.equal(pamxst [-icall], pamxoncest [-icall]), + all.equal(pamxoncest[-icall], pamxonce2st[-icall])) > > > ## Medoid bug --- MM: Fixed, well "0L+ hack", in my pam.q, on 2012-01-31 > ## ---------- > med0 <- (1:6) > st0 <- showSys.time(pamxst <- pam(x, 6, medoids = med0 , trace.lev=2)) C pam(): computing 3779876 dissimilarities from 2750 x 2 matrix: [Ok] pam()'s bswap(*, s=15.7788, pamonce=0): medoids given after build: medoids are 1 2 3 4 5 6 swp new 1421 <-> 6 old; decreasing diss. 20991.1 by -15949.5 swp new 2153 <-> 4 old; decreasing diss. 5041.66 by -1676.25 swp new 915 <-> 3 old; decreasing diss. 3365.41 by -1671.37 swp new 325 <-> 2 old; decreasing diss. 1694.04 by -53.8582 swp new 2720 <-> 5 old; decreasing diss. 1640.18 by -26.6572 swp new 2696 <-> 2153 old; decreasing diss. 1613.53 by -19.0531 swp new 52 <-> 1 old; decreasing diss. 1594.47 by -13.965 swp new 2709 <-> 2720 old; decreasing diss. 1580.51 by -5.81848 swp new 199 <-> 325 old; decreasing diss. 1574.69 by -2.65496 swp new 438 <-> 52 old; decreasing diss. 1572.03 by -1.77054 swp new 2082 <-> 2696 old; decreasing diss. 1570.26 by -0.187256 end{bswap()}, end{cstat()} Time user system elapsed Time 9.981 0.004 10.018 > stopifnot(identical(med0, 1:6)) > med0 <- (1:6) > st1 <- showSys.time(pamxst.1 <- pam(x, 6, medoids = med0 , pamonce=1, trace.lev=2)) C pam(): computing 3779876 dissimilarities from 2750 x 2 matrix: [Ok] pam()'s bswap(*, s=15.7788, pamonce=1): medoids given after build: medoids are 1 2 3 4 5 6 swp new 1421 <-> 6 old; decreasing diss. 20991.1 by -15949.5 swp new 2153 <-> 4 old; decreasing diss. 5041.66 by -1676.25 swp new 915 <-> 3 old; decreasing diss. 3365.41 by -1671.37 swp new 325 <-> 2 old; decreasing diss. 1694.04 by -53.8582 swp new 2720 <-> 5 old; decreasing diss. 1640.18 by -26.6572 swp new 2696 <-> 2153 old; decreasing diss. 1613.53 by -19.0531 swp new 52 <-> 1 old; decreasing diss. 1594.47 by -13.965 swp new 2709 <-> 2720 old; decreasing diss. 1580.51 by -5.81848 swp new 199 <-> 325 old; decreasing diss. 1574.69 by -2.65496 swp new 438 <-> 52 old; decreasing diss. 1572.03 by -1.77054 swp new 2082 <-> 2696 old; decreasing diss. 1570.26 by -0.187256 end{bswap()}, end{cstat()} Time user system elapsed Time 6.703 0.000 6.713 > stopifnot(identical(med0, 1:6)) > stopifnot(all.equal(pamxst[-icall], pamxst.1 [-icall])) > > > ## Last Line: > cat('Time elapsed: ', proc.time() - .proctime00,'\n') Time elapsed: 36.876 0.112 37.177 0 0 > > > proc.time() user system elapsed 37.116 0.156 37.452