-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_experiment.py
61 lines (48 loc) · 2.53 KB
/
run_experiment.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
import argparse
import numpy as np
import os
from algorithms import *
from concurrent.futures import ProcessPoolExecutor
from runner import utils
from runner.runner import run_ftrl
def run_exp(num_trials, game, T, seed, feedback, algs):
for i in range(len(algs)):
alg = algs[i][0]
params = algs[i][1]
print('==========Run experiments for {}=========='.format(alg.__name__))
dir_name = 'results/{}_feedback/{}/{}'.format(feedback, game, alg.__name__)
if not os.path.exists(dir_name):
os.makedirs(dir_name)
os.makedirs(dir_name + '/csv')
os.makedirs(dir_name + '/figure')
# set random seed
utils.set_random_seed(seed)
# run each algorithm
logs = [None] * num_trials
with ProcessPoolExecutor() as pool:
arguments = [[trial_id, game, T, np.random.randint(0, 2 ** 32), feedback, alg, params] for trial_id in range(num_trials)]
for trial_id, log in enumerate(pool.map(run_ftrl, *tuple(zip(*arguments)))):
logs[trial_id] = log
# save log
utils.save_and_summary_results(dir_name, logs)
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--game', default='biased_rps', type=str,
choices=['biased_rps', 'm_eq', *['random_utility/size{}'.format(s) for s in [2, 3, 5, 10, 50, 100]]], help='name of game')
parser.add_argument('--num_trials', type=int, default=1, help='number of trials to run experiments')
parser.add_argument('--T', type=int, default=10000, help='number of iterations')
parser.add_argument('--feedback', type=str, default='full', choices=['full', 'bandit'], help='feedback type')
parser.add_argument('--seed', type=int, default=0, help='random seed')
parser.add_argument('--random_init_strategy', action='store_true', help='whether to generate the initial strategy uniformly at random')
args = parser.parse_args()
# define algorithms
algs = [
(FTRL, {'random_init_strategy': args.random_init_strategy, 'eta': 0.1}),
(OFTRL, {'random_init_strategy': args.random_init_strategy, 'eta': 0.1}),
(MFTRL, {'random_init_strategy': args.random_init_strategy, 'eta': 0.1, 'mu': 0.01, 'update_freq': 4000}),
]
# run experiments
print('==========Run experiment over {} trials=========='.format(args.num_trials))
run_exp(args.num_trials, args.game, args.T, args.seed, args.feedback, algs)
if __name__ == '__main__':
main()