Revision | 6a3311f5ffd9127cc7d6df3975e921cb753ea6c0 (tree) |
---|---|
Zeit | 2020-11-17 21:25:12 |
Autor | Lorenzo Isella <lorenzo.isella@gmai...> |
Commiter | Lorenzo Isella |
I now use the furrr library to speed up the computations.
@@ -3,7 +3,7 @@ | ||
3 | 3 | library(tidyverse) |
4 | 4 | library(igraph) |
5 | 5 | library(viridis) |
6 | - | |
6 | +library(furrr) | |
7 | 7 | |
8 | 8 | source("/home/lorenzo/myprojects-hg/R-codes/stat_lib.R") |
9 | 9 |
@@ -15,38 +15,46 @@ | ||
15 | 15 | |
16 | 16 | golden_ratio <- golden() |
17 | 17 | |
18 | -generate_data <- 0 | |
18 | +generate_data <- 1 | |
19 | 19 | |
20 | 20 | cutoff <- 2.001 |
21 | 21 | |
22 | +n_cores <- 10 | |
23 | + | |
22 | 24 | k_min <- 3 |
23 | 25 | |
24 | 26 | kf_val <- 1.3 |
25 | -df_val <- 1.8 | |
27 | +df_val <- 1.6 | |
28 | + | |
29 | + | |
30 | + | |
31 | +plan(multicore(workers=return_cores(n_cores))) | |
32 | + | |
33 | + | |
26 | 34 | |
27 | 35 | if (generate_data==1) { |
28 | 36 | |
29 | -file_path <- "/home/lorenzo/MEGA/work/aggregates/big-cluster/" | |
37 | +file_path <- "./" | |
30 | 38 | |
31 | 39 | |
32 | 40 | |
33 | 41 | dat_files2 <- extract_file_list(file_path,".dat", full_path=1) |
34 | 42 | |
35 | 43 | |
36 | -graph_list <- map2(dat_files2,cutoff, function(x,y) get_network_from_table(x,y)) | |
44 | +graph_list <- future_map2(dat_files2,cutoff, function(x,y) get_network_from_table(x,y)) | |
37 | 45 | |
38 | 46 | print("I have the networks") |
39 | 47 | |
40 | 48 | saveRDS(graph_list, "graph_list.RDS") |
41 | 49 | |
42 | 50 | |
43 | -frag_dist <- map(graph_list, fragment_cluster) | |
51 | +frag_dist <- future_map(graph_list, fragment_cluster) | |
44 | 52 | |
45 | 53 | print("I finished the fragmentation") |
46 | 54 | |
47 | 55 | saveRDS(frag_dist, "frag_dist.RDS") |
48 | 56 | |
49 | -branch_size_dist <- map2(graph_list,k_min, function(x,y) remove_nodes_high_deg(x,y) ) | |
57 | +branch_size_dist <- future_map2(graph_list,k_min, function(x,y) remove_nodes_high_deg(x,y) ) | |
50 | 58 | |
51 | 59 | print("I have the branch distribution") |
52 | 60 |
@@ -58,17 +66,17 @@ | ||
58 | 66 | ## tv <- map2(graph_list,3, ~ remove_nodes_high_deg(.x,.y) ) |
59 | 67 | |
60 | 68 | |
61 | -small_frag_exp <- map(frag_dist, function(x) mean(x$n2)) %>% flatten_dbl | |
69 | +small_frag_exp <- future_map(frag_dist, function(x) mean(x$n2)) %>% flatten_dbl | |
62 | 70 | |
63 | 71 | saveRDS(small_frag_exp,"small_fragment_distribution.RDS") |
64 | 72 | |
65 | 73 | ## ## or using the tilde notation |
66 | 74 | ## tt <- map(frag_dist, ~ mean(.x$n2)) %>% flatten_dbl |
67 | 75 | |
68 | -number_mon <- map(graph_list, vcount) %>% flatten_int | |
76 | +number_mon <- future_map(graph_list, vcount) %>% flatten_int | |
69 | 77 | saveRDS(number_mon, "aggregate_sizes.RDS") |
70 | 78 | |
71 | -diam_list <- map(graph_list, diameter) %>% flatten_dbl | |
79 | +diam_list <- future_map(graph_list, diameter) %>% flatten_dbl | |
72 | 80 | |
73 | 81 | saveRDS(diam_list, "diameters_list.RDS") |
74 | 82 |