forked from plewczynski/cog-abm
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathhub_simulations_script.py
More file actions
65 lines (49 loc) · 2.11 KB
/
hub_simulations_script.py
File metadata and controls
65 lines (49 loc) · 2.11 KB
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
57
58
59
60
61
62
63
64
65
# -*- coding: utf-8 -*-
# /COG_SIM
import os
from multiprocessing import Pool
import pandas as pd # must be python2
N_PROC = 4
networks= ["hub_hearer", "hub_speaker", "env_shift_training_hub_speaker", "env_shift_training_hub_hearer"]
results = {"CSA", "DSA", "CLA", "DG_CLA", "cc"}
pool = Pool(processes=N_PROC)
# simulations
for i in xrange(20):
for network in networks:
res_fname = "results_of_simulation/hub_sim_results/results_{0}_to_clique{1}".format(network, i)
if not os.path.isfile(res_fname):
pool.apply_async(os.system, ["python2 cog_simulations/steels/steels_main.py -s examples/simulations/hub_simulations/simulation_{0}_to_clique.json -r {1}".format(network, res_fname)])
pool.close()
pool.join()
pool = Pool(processes=N_PROC)
# analyzer
for i in xrange(20):
for result in results:
for network in networks:
res_fname = "results_of_simulation/hub_sim_data/data{0}{2}_{1}".format(network, i, result)
if not os.path.isfile(res_fname):
pool.apply_async(os.system, ["python2 cog_simulations/steels/analyzer.py -r results_of_simulation/hub_sim_results/results_{0}_to_clique{1} it {2} > {3}".format(network, i, result, res_fname)])
pool.close()
pool.join()
# pandas
index = range(0, 20010, 50)
columns = []
for result in results:
columns.append(result + "_mean")
columns.append(result + "_var")
mindex = pd.MultiIndex.from_product((networks, index))
data = pd.DataFrame(index=mindex, columns=columns)
networks= ["hub_hearer", "hub_speaker"]
for result in results:
for network in networks:
mean = pd.DataFrame(index=index)
var = pd.DataFrame(index=index)
for i in xrange(20):
data_sim = pd.read_csv(
"results_of_simulation/hub_sim_data/data{0}{1}_{2}".format(network, result, i), delim_whitespace=True, header=None, index_col=0)
mean[i] = (data_sim.mean(1))
var[i] = (data_sim.var(1))
data[result + "_mean"][network] = mean.mean(1)
data[result + "_var"][network] = var.mean(1)
with open("simulations_hub_sim_results.csv", 'w') as f:
data.to_csv(f)