-
Notifications
You must be signed in to change notification settings - Fork 0
/
RunEFR-CCE.py
77 lines (61 loc) · 2.39 KB
/
RunEFR-CCE.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
# Copyright 2019 DeepMind Technologies Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Example use of the CFR algorithm on Kuhn Poker."""
import pandas as pd
import time
import sys
import EFR
from open_spiel.python.algorithms import exploitability
from open_spiel.python.algorithms import cfr
from open_spiel.python import policy
from multiprocessing import Pool
import StoreTabularPolicy
import pyspiel
FL_game = 'kuhn_poker'
FL_iterations = 2
FL_players = 3
FL_print_freq = 1
FL_Runname = "Test run"
try:
FL_Runname = sys.argv[1]
except:
pass
try:
FL_iterations = int(sys.argv[2])
print(FL_iterations)
except:
pass
def main(deviation):
header = ['Iteration', 'Distance to CCE']#, 'Average Payoff', 'Value compared to uniform']
efr_data = []
game = pyspiel.load_game(FL_game, {"players": FL_players})
efr_solver = EFR.EFRSolver(game, deviation)
strategies = []
for i in range(FL_iterations):
EFR_iteration_data = [i]
efr_solver.evaluate_and_update_policy()
if i % FL_print_freq == 0:
strategies.append(policy.python_policy_to_pyspiel_policy(
efr_solver.current_policy()))
corr_dev = pyspiel.uniform_correlation_device(strategies)
cce_dist_info = pyspiel.cce_dist(game, corr_dev)
print("EFR {} Iteration {} distance to coarse correlated {}".format(deviation, str(i), cce_dist_info.dist_value))
EFR_iteration_data.append(cce_dist_info.dist_value)
efr_data.append(EFR_iteration_data)
print ("##########################################")
EFR_data = pd.DataFrame(efr_data, columns=header)
EFR_data.to_csv(deviation+ " "+ FL_Runname+'EFR_CCE_3player.csv', index=False)
with Pool(processes=8) as pool:
deviation_types = ["blind action", "informed action", "blind cf", "informed cf", "bps", "cfps", "csps", "tips", "bhv"]
pool.map(main, deviation_types)