Files
katrain-qt/test_report.py
T
+3 bf70f2cf23 1.9 dev (#411)
* refactor priorities

* performance report doodling

* shutup pycharm

* more doodling

* doodle tricol

* tweak report, fix bug in insert

* reorder colors

* another metric

* sorting engines, trying to catch exc

* restructure engine err

* restructure engine err

* test stuff

* test report

* test report

* test and readme

* test and readme

* layout

* engine recov

* pixelfix and exes

* readme

* keyboard shortcut override

* oops

* mistakes only deeper

* black and readme

* readme

* fix #421, scale repor

* Add shortcut variables (#420)

* Add shortcut variables

* Address comments and missed shortcuts

* fix shortcuts

* rename, design report, fix report

* make translators work more

* relative mid/opening/endgame bounds

* win size dbg

* more errros

* entry

* jeff mode

* fix

* readme

* edit THEMES.md

* edit katrain/core/ai.py, edit katrain/gui/kivyutils.py

* jp (#423)

* edit THEMES.md

* edit katrain/__main__.py, edit katrain/gui/kivyutils.py and 1 other changes

* Update katrain.po (#425)

1.9 first French .po

* edit katrain/i18n/locales/fr/LC_MESSAGES/katrain.mo

* edit katrain/core/ai.py, edit katrain/gui/popups.py

* bluedabadee

* fix sgf and black

* edit katrain/i18n/locales/fr/LC_MESSAGES/katrain.po

* ko

* Update zh-TW translation (#426)

* cn

* cn

* Some corrections to Chinese translations (#427)

* some corrections in cn and tw

* better trans

* edit CONTRIBUTIONS.md, edit katrain/i18n/locales/cn/LC_MESSAGES/katrain.mo and 1 other changes

* de

* tw

* player what only

* add green background to better value (#428)

* edit katrain/gui/popups.py, edit katrain/gui/theme.py

* Russian for 1.9 (#432)

* edit katrain/i18n/locales/ru/LC_MESSAGES/katrain.po, edit katrain/gui.kv and 1 other changes

* sound fix

* sound fix

* fmt

* fix sound

* edit THEMES.md, edit CONTRIBUTIONS.md and 1 other changes

* sound fix

* Do not use ffpyplayer on Windows (#434)

* edit katrain/gui/sound.py

* no pr

* jeff theme

* stopsound

* sound and theme fix

* font fix and more errs

* French po corrections (#441)

Former translations were misleading. It should be accurate now.

* add mouse scroll to browser through node variations. (#442)

* add mouse scroll to browser through node variations.

* add mouse scroll to browser through node variations.

* add mouse scroll to browser through node variations.

* edit katrain/popups.kv, edit katrain/__main__.py and 2 other changes

* windows binary, black

* linux binary

* edit INSTALL.md

* edit .github/workflows/osxbuild.yaml

* edit .github/workflows/osxbuild.yaml

* edit .github/workflows/osxbuild.yaml

Co-authored-by: Sander Land <sander.land@cognite.com>
Co-authored-by: roux g. buciu <11182210+electricRGB@users.noreply.github.com>
Co-authored-by: kaorahi <38910552+kaorahi@users.noreply.github.com>
Co-authored-by: Dontbtme <66470440+Dontbtme@users.noreply.github.com>
Co-authored-by: Liou, Guan-Cheng <Tony-Liou@users.noreply.github.com>
Co-authored-by: Ching-yu Lin <60384727+chingyulin@users.noreply.github.com>
Co-authored-by: xiaoyifang <105986+xiaoyifang@users.noreply.github.com>
Co-authored-by: Alexander Kiselev <satoshi.yoda.register.264@gmail.com>
Co-authored-by: Sander Land <Sander@bioeng219-lap.isd.kcl.ac.uk>
Co-authored-by: Carton He <cartonhe@gmail.com>
Co-authored-by: Sander Land <sander.land@aroni.fritz.box>
Co-authored-by: Sander Land <sander.land@futurefacts.nl>
2021-06-28 16:59:17 +02:00

108 lines
3.1 KiB
Python

import os
import time
import pandas as pd
import numpy as np
from unidecode import unidecode
from katrain.core.ai import game_report
from katrain.core.base_katrain import KaTrainBase
from katrain.core.engine import KataGoEngine
from katrain.core.game import KaTrainSGF, Game
import matplotlib.pyplot as plt
pd.set_option("display.max_rows", 5000)
settings = {
"fast_visits": 25,
"max_visits": 500,
"threads": 64,
"model": "C:\\Users\\sande\\.katrain\\kata1-b40c256-s7907049728-d1917596640.bin.gz",
}
# settings["model"] = "C:\\Users\\sande\\.katrain\\g170e-b20c256x2-s5303129600-d1228401921.bin.gz"
def dan(rank):
rank = rank.lower()
if rank[-1] in ["d", "p"]:
return int(rank[:-1])
elif rank == "?":
return np.nan
else:
assert rank[-1] == "k", f"unexpected rank {rank}"
return 1 - int(rank[:-1])
def polyfit(x, y, degree=1):
coeffs = np.polyfit(x, y, degree)
correlation = np.corrcoef(x, y)[0, 1]
results = {"coef": coeffs.tolist(), "r": correlation, "rsq": correlation ** 2}
return results
katrain = KaTrainBase(force_package_config=True, debug_level=0)
combined_settings = {**katrain.config("engine"), **settings}
engine = KataGoEngine(katrain, {**katrain.config("engine"), **settings})
thresholds = katrain.config("trainer/eval_thresholds")
games = []
n = 0
for sgf in os.listdir("sgftest/"):
if sgf.lower().endswith("sgf"):
print(sgf)
with open(os.path.join("sgftest", sgf)) as f:
move_tree = KaTrainSGF.parse_sgf(f.read())
games.append(Game(katrain, engine, move_tree=move_tree, analyze_fast=False))
n += 1
if n >= 30000: # small test=3
break
while not engine.is_idle():
print(f"waiting for engine to finish...{engine.queries_remaining()} queries left")
time.sleep(0.5)
engine.shutdown(finish=None)
reports = []
for game in games:
sum_stats, _, _ = game_report(game, thresholds=thresholds)
for bw in "BW":
oppbw = "B" if bw == "W" else "W"
info = {
f"name": game.root.get_property(f"P{bw}", "??"),
"rank": game.root.get_property(f"{bw}R", "9p"),
"opp_rank": game.root.get_property(f"{oppbw}R", "9p"),
**sum_stats[bw],
}
reports.append(info)
df = pd.DataFrame(reports).sort_values(by="accuracy", ascending=False).reset_index(drop=True)
df.name = [unidecode(n) for n in df.name]
print(df)
df["numrank"] = [dan(rank) for rank in df["rank"]]
def subplot(sp, ynames):
global df
plt.subplot(2, 2, sp)
legend = []
xfull = np.array(range(df["numrank"].min(), df["numrank"].max() + 1))
cols = "bgr"
for i, yname in enumerate(ynames):
plt.plot(df["numrank"], df[yname], cols[i] + "x")
for i, yname in enumerate(ynames):
fit = polyfit(df["numrank"], df[yname])
a, b = fit["coef"]
plt.plot(xfull, xfull * a + b, cols[i] + ":")
legend.append(f"{yname}: r^2 = {fit['rsq']:.3f}")
plt.xlabel("dan rank")
plt.legend(legend)
plt.subplots(2, 2)
subplot(1, ["accuracy"])
subplot(2, ["complexity"])
subplot(3, ["ai_top_move", "ai_top5_move"])
subplot(4, ["mean_ptloss", "weighted_ptloss"])
plt.show()