Commit 0d786cc1 by songxinkai

draw plot: analysis.py, tested ok!

parent 9a784a4c
.*swp
.*swo
.*swn
.*swm
core.*
......@@ -13,8 +13,7 @@ def main():
assert(mlu_id < 4 and mlu_id >= 0)
context = zmq.Context()
socket = context.socket(zmq.REQ)
# socket.connect('tcp://10.34.134.204:1238')
socket.connect('tcp://10.37.199.62:1238')
socket.connect('tcp://10.39.252.50:1238')
socket.send('')
while True:
task = socket.recv().split('-')
......
......@@ -4,13 +4,11 @@ import sys
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
model={}
routines = []
labels = routines
smooth_window = 10
# labels = ['test17', 'test18']
filename = 'output.txt'
filename = 'outputs/10-09_00-30-47'
if len(sys.argv) == 2:
filename = sys.argv[1]
with open(filename, 'r') as f:
......@@ -19,36 +17,33 @@ with open(filename, 'r') as f:
#if l.startswith('R') or l.startswith('D') or l.startswith('s'):
# l = l.strip()
# model[l.split()[0]] = float(l.split()[1])
model_name = l.strip().split()[0]
if int(model_name.split("_")[1]) > 150000:
model_name = l.strip().split(" ")[0]
if int(model_name.split("_")[-1].split(".")[0]) > 450000:
continue
model[model_name] = float(l.split()[1])
routine = model_name.split('_')[0]
model[model_name] = float(l.split(" ")[1])
routine = int(model_name.split('test_')[-1].split("/")[0])
if routine not in routines:
routines.append(routine)
print (model)
def getInfo(k):
ks = k.split('_')
key = '_'.join(ks[0:len(ks) - 1])
i = int(ks[-1])
return key, i
def getInfo(model_name):
test_id = int(model_name.split("test_")[-1].split("/")[0])
iter_id = int(model_name.split("_")[-1].split(".")[0])
return test_id, iter_id
def cmpKey(k1, k2):
k1 = k1[0]
k2 = k2[0]
key1, i1 = getInfo(k1)
key2, i2 = getInfo(k2)
if (key1 != key2):
return -1 if key1 < key2 else 1
model_name_1 = k1[0]
model_name_2 = k2[0]
test_id_1, iter_id_1 = getInfo(model_name_1)
test_id_2, iter_id_2 = getInfo(model_name_2)
if (test_id_1 != test_id_2):
return -1 if test_id_1 < test_id_2 else 1
else:
return i1 - i2
return iter_id_1 - iter_id_2
smodel = model.items()
print(smodel)
smodel.sort(cmp = cmpKey)
print(smodel)
def smooth(x, N):
y = []
......@@ -57,19 +52,18 @@ def smooth(x, N):
return y
from scipy.interpolate import spline
def getPlot(mp, key):
def getPlot(models, key_test_id):
x = []
y = []
for k, v in mp:
kkey, ki = getInfo(k)
if kkey == key:
if ki > 500 or ki == 0:
x.append(ki)
y.append(v)
for model_name, score in models:
test_id, iter_id = getInfo(model_name)
if test_id == key_test_id:
x.append(iter_id)
y.append(score)
# new_x = np.linspace(min(x), max(x), 300)
# new_y = spline(x, y, new_x)
new_x = x
# new_y = y
#new_y = y
new_y = smooth(y, smooth_window)
return new_x, new_y
# def getStr(key):
......@@ -82,17 +76,19 @@ def getPlot(mp, key):
# plt.figure(figsize=(16,12), dpi=200)
#plt.xlim(0,50000)
font_size = 12
labels_ = {73: "100", 74: "200", 77: "50", 78: "1600", 79: "400", 80: "800"}
# labels_ = {73: "100", 74: "200", 77: "50", 78: "1600", 79: "400", 80: "800"}
labels_ = {r:str(r) for r in routines}
# for i in range(len(routines)):
for i in [0]:
print (routines, labels_)
for r in routines:
# if not int(routines[i].split("test")[-1]) in [90, 92, 93]:
# continue
if int(routines[i].split("test")[-1]) not in labels_.keys():
if r not in labels_.keys():
continue
plt.plot(*getPlot(smodel, routines[i]), linestyle='-', label=labels_[int(routines[i].split("test")[-1])])
plt.plot(*getPlot(smodel, r), linestyle='-', label=labels_[r])
# plt.plot(*getPlot(smodel, routines[i]), linestyle='-', label=routines[i])
plt.xlabel("Training Iteration", fontsize=font_size)
plt.ylabel("Elo-Rating", fontsize=font_size)
# plt.legend(loc="lower left", fontsize=font_size)
plt.legend(loc="lower left", fontsize=font_size)
plt.show()
plt.savefig('figure.png')
......@@ -213,9 +213,9 @@ class EloRatingSystem:
players=self.getPlayers(sortByRank)
with open(saveFile,'w') as f:
f.write('{:<60s}{:<10s}{:<10s}{:<10s}{:<10s}\n'.format('model','rating','games','wins','losses'))
f.write('{:<80s}{:<10s}{:<10s}{:<10s}{:<10s}\n'.format('model','rating','games','wins','losses'))
for p in players:
f.write('{:<60s}{:<10.2f}{:<10d}{:<10d}{:<10d}\n'.format(str(p.name),p.rating,p.num_game,p.wins,p.losses))
f.write('{:<80s}{:<10.2f}{:<10d}{:<10d}{:<10d}\n'.format(str(p.name),p.rating,p.num_game,p.wins,p.losses))
def getPlayers(self,sortByRank=False):
......
No preview for this file type
figure.png

24.9 KB | W: | H:

figure.png

27.7 KB | W: | H:

figure.png
figure.png
figure.png
figure.png
  • 2-up
  • Swipe
  • Onion skin
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -8,7 +8,7 @@ for test_id in test_ids:
model_prefix = "/share/backup_data/go9/test_%d/off_models/go9_iter_"%(test_id)
model_suffix = ".cambricon"
i = 0
delta = 10000
delta = 2000
while True:
model_path = "%s%d%s"%(model_prefix, i, model_suffix)
if not os.path.exists(model_path):
......
......@@ -2,6 +2,6 @@ config_p1_eval: /share/alphazero-general/go9/etc/pk_p1_eval.conf
config_p1_mcts: /share/alphazero-general/go9/etc/pk_p1_mcts.conf
config_p2_eval: /share/alphazero-general/go9/etc/pk_p2_eval.conf
config_p2_mcts: /share/alphazero-general/go9/etc/pk_p2_mcts.conf
model_p1: /share/backup_data/go9/test_1/off_models/go9_iter_160000.cambricon
model_p2: /share/backup_data/go9/test_0/off_models/go9_iter_260000.cambricon
P2 win rat
\ No newline at end of file
model_p1: /share/backup_data/go9/test_0/off_models/go9_iter_156000.cambricon
model_p2: /share/backup_data/go9/test_0/off_models/go9_iter_222000.cambricon
P2 win rate1
\ No newline at end of file
......@@ -3,5 +3,6 @@ ulimit -c 0
apt-get update
apt-get install -y python-zmq
cd /share/elo-rating
./ELO_client_test.py 0 & ./ELO_client_test.py 1 & ./ELO_client_test.py 2 & ./ELO_client_test.py 3 & \
./ELO_client_test.py 0 & ./ELO_client_test.py 1 & ./ELO_client_test.py 2 & ./ELO_client_test.py 3
# ./ELO_client.py 0 & ./ELO_client.py 1 & ./ELO_client.py 2 & ./ELO_client.py 3
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment