-
Notifications
You must be signed in to change notification settings - Fork 1
/
simulation.R
56 lines (46 loc) · 1.35 KB
/
simulation.R
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
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
53
54
55
56
library(DFNET)
source(here::here("examples", "barabasi", "graph.R"))
input <- NULL
while (is.null(input)) {
tryCatch(
{
input <- simple_input_graph(n.nodes = 20)
},
error = function(e) {
message("failed to create a graph, retrying...")
}
)
}
graph <- input$graph
features <- input$features
target <- input$target
forest <- train(, graph, features, target, ntrees = 100, niter = 10)
# XXX: public metrics
tree_imp <- sapply(
forest$trees,
function(tree) ModelMetrics::auc(target, tree$predictions)
)
edge_imp <- edge_importance(graph, forest$trees, tree_imp)
print(edge_imp)
umi <- unique_module_importance(graph, forest$modules, edge_imp, tree_imp)
by_importance <- order(umi$table[, "total"], decreasing = TRUE)
detected_module <- unlist(umi$modules[by_importance][1])
print(head(umi$table[by_importance, ]))
print(unique(sort(input$module)))
edgelist <- as_edgelist(graph, names = FALSE)
color <- rep("cadetblue", dim(edgelist)[1])
for (e in 1:dim(edgelist)[1]) {
edge <- edgelist[e, 1:2]
ids <- match(edge, detected_module)
if (!any(is.na(ids))) {
color[e] <- "coral2"
}
}
plot(
graph,
edge.width = exp(edge_imp + 1), edge.color = color,
vertex.shape = "none",
# use numeric labels again
vertex.label = 1:length(V(graph)),
vertex.label.color = "black"
)