@@ -32,7 +32,7 @@ create_clusters <- function(distance_matrix, max_clusters=-1, method="ward.D") {
3232 num_clusters <- tryCatch({
3333 cut_off <- get_cut_off(css_cluster , attempt )
3434 attempt <- attempt + 1
35- if (attempt > 500 ) cut_off $ k else NA
35+ if (attempt > 250 ) cut_off $ k else max_clusters
3636 }, error = function (err ){
3737 vclog $ debug(err $ message )
3838 return (NA )
@@ -102,7 +102,8 @@ get_ndms <- function(distance_matrix, mindim=2, maxdim=2) {
102102 # Perform non-metric multidimensional scaling
103103 # nm <- par.nmds(distance_matrix, mindim=mindim, maxdim=maxdim, maxit=maxit)
104104 # nm.nmin = nmds.min(nm)
105- if (nrow(distance_matrix ) < = 2 ) {
105+ dm_nrows <- max(nrow(distance_matrix ),1 )
106+ if (dm_nrows < = 2 ) {
106107 points <- tryCatch({
107108 ord <- metaMDS(distance_matrix , k = 2 , parallel = 7 , trymax = 30 ,
108109 engine = " monoMDS" , distance = ' cao' ,
@@ -114,12 +115,13 @@ get_ndms <- function(distance_matrix, mindim=2, maxdim=2) {
114115 vclog $ info(paste(" vis_id:" , .GlobalEnv $ VIS_ID , " NMDS-Stress:" , min(ord $ stress ), sep = " " ))
115116 points <- ord $ points
116117 }, error = function (err ){
117- points <- cbind(runif(nrow( distance_matrix ) , min = - 1 , max = 0 ),
118- runif(nrow( distance_matrix ) , min = 0 , max = 1 ))
118+ points <- cbind(runif(dm_nrows , min = - 1 , max = 0 ),
119+ runif(dm_nrows , min = 0 , max = 1 ))
119120 return (points )
120121 })
121- } else if (nrow(distance_matrix ) == 1 ) {
122- points <- cbind(0 , 0 )
122+ } else if (dm_nrows == 0 ) {
123+ points <- cbind(runif(1 , min = - 1 , max = 0 ),
124+ runif(1 , min = 0 , max = 1 ))
123125 } else {
124126 points <- tryCatch({
125127 ord <- metaMDS(distance_matrix , k = 2 , parallel = 7 , trymax = 30 ,
@@ -132,8 +134,8 @@ get_ndms <- function(distance_matrix, mindim=2, maxdim=2) {
132134 vclog $ info(paste(" vis_id:" , .GlobalEnv $ VIS_ID , " NMDS-Stress:" , min(ord $ stress ), sep = " " ))
133135 points <- ord $ points
134136 }, error = function (err ){
135- points <- cbind(runif(nrow( distance_matrix ) , min = - 1 , max = 0 ),
136- runif(nrow( distance_matrix ) , min = 0 , max = 1 ))
137+ points <- cbind(runif(dm_nrows , min = - 1 , max = 0 ),
138+ runif(dm_nrows , min = 0 , max = 1 ))
137139 return (points )
138140 })
139141 }
0 commit comments