-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_simulation.py
127 lines (116 loc) · 2.83 KB
/
run_simulation.py
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import simulations
import extremity_game
import belief_game
from optparse import OptionParser
parser = OptionParser()
parser.add_option(
"--name",
default="signaling_game_simulation",
dest="simulation_name",
help="Simulation name",
)
parser.add_option(
"--game",
default="extremity",
dest="game_type",
help='Game type, "extremity" or "belief". Default: "extremity"',
)
parser.add_option(
"-m",
"--message",
default="2",
dest="message_sizes",
help="Message dimension. Default: 2",
)
parser.add_option(
"-o",
"--object",
default="5",
dest="object_size",
help="Object dimension. Default: 5",
)
parser.add_option(
"--strict",
default="true",
dest="strict_context",
help="Context strictness. Default: true",
)
parser.add_option(
"--shared",
default="true",
dest="shared_context",
help="Shared or non-shared context (displacement). Default: true",
)
parser.add_option(
"--objects",
default="10",
dest="num_objects",
help="Number of objects in context. Used only for non-strict contexts. Default: 10",
)
parser.add_option(
"--batch-size",
default="128",
dest="mini_batch_size",
help="Minibatch size. Default: 128",
)
parser.add_option(
"-b",
"--batches",
default="5000",
dest="num_batches",
help="Number of batches. Default: 5000",
)
parser.add_option(
"-t",
"--trials",
default=1,
type="int",
dest="num_trials",
help="Number of trials (reproductions) for each game. Default: 1",
)
parser.add_option(
"-p",
"--processes",
default=8,
type="int",
dest="num_processes",
help="Number of games to run in parallel. Default: 8",
)
(options, args) = parser.parse_args()
iterable_args = (
"message_sizes",
"object_size",
"strict_context",
"shared_context",
"num_objects",
"mini_batch_size",
"num_batches",
)
game_type_to_factory = {
"extremity": extremity_game.make_extremity_game_simulation,
"belief": belief_game.make_belief_update_simulation,
}
kwargs = {}
for option, option_val in options.__dict__.items():
if option == "game_type":
try:
factory = game_type_to_factory[option_val]
kwargs["simulation_factory"] = factory
except KeyError:
parser.print_help()
parser.error("Invalid game type.")
elif option in iterable_args:
vals = []
string_vals = option_val.split(",")
for str_val in string_vals:
str_val = str_val.strip().lower()
if str_val == "true":
vals.append(True)
elif str_val == "false":
vals.append(False)
else:
vals.append(int(str_val))
kwargs[option] = tuple(vals)
else:
kwargs[option] = option_val
simulations.run_simulation_grid(**kwargs)