Моя R-программа выглядит следующим образом:
hcluster <- function(dmatrix) {
imatrix <- NULL
hc <- hclust(dist(dmatrix), method="average")
for(h in sort(unique(hc$height))) {
hc.index <- c(h,as.vector(cutree(hc,h=h)))
imatrix <- cbind(imatrix, hc.index)
}
return(imatrix)
}
dmatrix_file = commandArgs(trailingOnly = TRUE)[1]
print(paste('Reading distance matrix from', dmatrix_file))
dmatrix <- as.matrix(read.csv(dmatrix_file,header=FALSE))
imatrix <- hcluster(dmatrix)
imatrix_file = paste("results",dmatrix_file,sep="-")
print(paste('Wrinting results to', imatrix_file))
write.table(imatrix, file=imatrix_file, sep=",", quote=FALSE, row.names=FALSE, col.names=FALSE)
print('done!')
Мой вход - матрица расстояний (конечно, симметричная).Когда я выполняю вышеупомянутую программу с матрицей расстояний, превышающей примерно тысячи записей (ничего не происходит в течение нескольких сотен), она выдает мне сообщение об ошибке:
Error in cutree(hc, h = h) :
the 'height' component of 'tree' is not sorted
(increasingly); consider applying as.hclust() first
Calls: hcluster -> as.vector -> cutree
Execution halted
Моя машина имеет около 16 ГБ ОЗУ и 4CPU, поэтомуне будет проблемой ресурсов.
Может кто-нибудь, пожалуйста, дайте мне знать, в чем проблема?Спасибо !!