r other_clustering.r
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了r other_clustering.r相关的知识,希望对你有一定的参考价值。
g_adjmatrix <- get.adjacency(graph=g_mock, type="both", sparse = F, attr = "weight")
ap_bin <- "python3 ~/Downloads/apcluster.py"
ap_pyth <- run_ap(X = "g_mock", adj_mat = as.matrix(g_adjmatrix), ap_bin = ap_bin, damping = 0.8, maxit = 500, covit = 25)
clust_ap_pyth <- ap_pyth$com[match(get.vertex.attribute(g_mock, "name"), ap_pyth$vertex) ] %>% as.numeric
com_app <- make_clusters(g_mock, clust_ap_pyth + 1, algorithm = 'APp', modularity = TRUE)
V(g_mock)$com_app <- as.character(membership(com_app))
g_adjmatrix <- as_adjacency_matrix(graph=g_mock, type="both", sparse = F, attr = "weight")
hd_bin <- "~/Downloads/hdb.py"
hd_pyth <- run_hdbscan(X = "g_mock", adj_mat = as.matrix(1 - g_adjmatrix), hdbscan_bin = hd_bin, alpha = 1, min_cluster_size = 2, min_samples = 1)
## Parsing AP output. 21 communities detected.
clust_hd_pyth <- hd_pyth$com[match(get.vertex.attribute(g_mock, "name"), hd_pyth$vertex) ] %>% as.numeric
clust_hdb <- make_clusters(g_mock, clust_hd_pyth + 2, algorithm = 'hdbscan', modularity = TRUE)
V(g_mock)$com_hdb <- as.character(membership(clust_hdb))
########
run_ap <- function(X, adj_mat = adj_mat, damping = 0.8, maxit = 500, covit = 25, ap_bin = ap_bin, preference = 'None'){
out_file <- paste("~/Downloads/", X,"-ap.out", sep = "")
g_name <- paste("~/Downloads/", X,".csv", sep = "")
ap_command <- paste(ap_bin, g_name, out_file, damping, maxit, covit, preference, sep = " ")
write.table(adj_mat, file = g_name, sep = ",", quote = F )
system(ap_command)
#map_file <- paste(out_folder, "/", X, ".map", sep = "")
ap_results <- parse_ap(out_file)
}
run_hdbscan <- function(X, adj_mat = adj_mat , hdbscan_bin = hdbscan_bin, alpha = 1.0, min_samples = "None", min_cluster_size = 5){
out_file <- paste("~/Downloads/", X,"-hdbscan.out", sep = "")
g_name <- paste("~/Downloads/", X,".csv", sep = "")
ap_command <- paste(hdbscan_bin, g_name, out_file, alpha, min_cluster_size, min_samples, sep = " ")
write.table(adj_mat, file = g_name, sep = ",", quote = F )
system(ap_command)
#map_file <- paste(out_folder, "/", X, ".map", sep = "")
ap_results <- parse_ap(out_file)
}
# Parse AP results -------------------------------------------------------
parse_ap <- function(X){
modules <- read.table(file = X, stringsAsFactors = F, sep = "\t") %>%
set_colnames(c("vertex", "com"))
cat(paste("Parsing AP output.", length(unique(modules$com)), "communities detected.\n"))
com <- modules
}
以上是关于r other_clustering.r的主要内容,如果未能解决你的问题,请参考以下文章
——R的数据组织
+-r, +-s 的所有排列
shinydashboard ui.R 和 server.R 未读取 Global.R
R语言计算回归模型R方(R-Squared)实战
r语言中r-studio怎么调用
R电子书资料《学习R》+《R语言实战第2版》+《R数据科学》学习推荐