-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from kobanium/develop
Develop
- Loading branch information
Showing
19 changed files
with
1,181 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
from cshogi import * | ||
from cshogi import CSA | ||
import numpy as np | ||
import sys | ||
import os | ||
import glob | ||
import math | ||
import argparse | ||
|
||
HuffmanCodedPosAndEval3 = np.dtype([ | ||
('hcp', dtypeHcp), # 開始局面 | ||
('moveNum', np.uint16), # 手数 | ||
('result', np.uint8), # 結果(xxxxxx11:勝敗、xxxxx1xx:千日手、xxxx1xxx:入玉宣言、xxx1xxxx:最大手数) | ||
('opponent', np.uint8), # 対戦相手(0:自己対局、1:先手usi、2:後手usi) | ||
]) | ||
MoveInfo = np.dtype([ | ||
('selectedMove16', dtypeMove16), # 指し手 | ||
('eval', dtypeEval), # 評価値 | ||
('candidateNum', np.uint16), # 候補手の数 | ||
]) | ||
MoveVisits = np.dtype([ | ||
('move16', dtypeMove16), # 候補手 | ||
('visitNum', np.uint16), # 訪問回数 | ||
]) | ||
|
||
ENDGAME_SYMBOLS = { | ||
1 : '%TORYO', | ||
2 : '%TORYO', | ||
4 : '%SENNICHITE', | ||
9 : '%KACHI', | ||
10: '%KACHI', | ||
16: '%CHUDAN', | ||
} | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument('hcpe3') | ||
parser.add_argument('csa') | ||
parser.add_argument('--range') | ||
parser.add_argument('--nyugyoku', action='store_true') | ||
parser.add_argument('--aoba', action='store_true') | ||
parser.add_argument('--out_v', action='store_true') | ||
parser.add_argument('--sort_visits', action='store_true') | ||
args = parser.parse_args() | ||
|
||
f = open(args.hcpe3, 'rb') | ||
|
||
if args.aoba: | ||
sep = ',' | ||
else: | ||
sep = '\n' | ||
|
||
if args.range: | ||
start_end = args.range.split(':') | ||
if len(start_end) == 1: | ||
start = int(start_end[0]) | ||
end = start + 1 | ||
else: | ||
if start_end[0] == '': | ||
start = 0 | ||
else: | ||
start = int(start_end[0]) | ||
if start_end[1] == '': | ||
end = sys.maxsize | ||
else: | ||
end = int(start_end[1]) | ||
else: | ||
start = 0 | ||
end = sys.maxsize | ||
|
||
board = Board() | ||
csa = CSA.Exporter(args.csa) | ||
v_pos_sum = 0 | ||
move_sum = 0 | ||
p = 0 | ||
while p < end: | ||
data = f.read(HuffmanCodedPosAndEval3.itemsize) | ||
if len(data) == 0: | ||
break | ||
hcpe = np.frombuffer(data, HuffmanCodedPosAndEval3, 1)[0] | ||
board.set_hcp(hcpe['hcp']) | ||
assert board.is_ok() | ||
move_num = hcpe['moveNum'] | ||
result = hcpe['result'] | ||
move_sum += move_num | ||
need_output = p >= start and (not args.nyugyoku or result & 8 != 0) | ||
if need_output: | ||
# csa.info(board, comments=[f"moveNum={move_num},result={result},opponent={hcpe['opponent']}"]) | ||
print ("'move_num=" +str(move_num) +",result=" +str(result)+ ",opponent=" + str(hcpe['opponent'])) | ||
print (board) | ||
for i in range(move_num): | ||
move_info = np.frombuffer(f.read(MoveInfo.itemsize), MoveInfo, 1)[0] | ||
candidate_num = move_info['candidateNum'] | ||
move_visits = np.frombuffer(f.read(MoveVisits.itemsize * candidate_num), MoveVisits, candidate_num) | ||
move = board.move_from_move16(move_info['selectedMove16']) | ||
if need_output: | ||
if candidate_num > 0: | ||
v_pos_sum += 1 | ||
if args.aoba: | ||
if args.out_v: | ||
v = 1.0 / (1.0 + math.exp(-move_info['eval'] * 0.0013226)) | ||
comment = f"v={v:.3f}," | ||
else: | ||
comment = '' | ||
comment += f"{move_visits['visitNum'].sum()}" | ||
if args.sort_visits: | ||
move_visits = np.sort(move_visits, order='visitNum')[::-1] | ||
for move16, visit_num in zip(move_visits['move16'], move_visits['visitNum']): | ||
comment += ',' + move_to_csa(board.move_from_move16(move16)) + ',' + str(visit_num) | ||
else: | ||
comment = '** ' + str(move_info['eval'] * (1 - board.turn * 2)) | ||
else: | ||
if args.aoba or move_info['eval'] == 0: | ||
# comment = None | ||
comment = "" | ||
else: | ||
comment = '** ' + str(move_info['eval'] * (1 - board.turn * 2)) | ||
# csa.move(move, comment=comment, sep=sep) | ||
# csa.move(move, sep=sep) | ||
if (board.turn) == 0: | ||
sen = "+" | ||
else: | ||
sen = "-" | ||
print (sen + move_to_csa(move) + ",'" + comment) | ||
board.push(move) | ||
assert board.is_ok() | ||
if need_output: | ||
print (ENDGAME_SYMBOLS[hcpe['result']]) | ||
print ("/") | ||
# csa.endgame(ENDGAME_SYMBOLS[hcpe['result']]) | ||
p += 1 | ||
print (p,move_sum,v_pos_sum) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from cshogi import * | ||
import numpy as np | ||
import math | ||
|
||
import argparse | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument('hcpe') | ||
#parser.add_argument('psv') | ||
args = parser.parse_args() | ||
|
||
hcpes = np.fromfile(args.hcpe, dtype=HuffmanCodedPosAndEval) | ||
#psvs = np.zeros(len(hcpes), PackedSfenValue) | ||
move_sum = 0 | ||
res = [0,0,0] | ||
s_max = -999999 | ||
s_min = +999999 | ||
board = Board() | ||
for hcpe in hcpes: | ||
#for hcpe in zip(hcpes): | ||
board.set_hcp(hcpe['hcp']) | ||
# board.to_psfen(psv['sfen']) | ||
score = hcpe['eval'] | ||
move16 = hcpe['bestMove16'] | ||
move_csa = move_to_csa(board.move_from_move16(move16)) | ||
#move_num = hcpe['moveNum'] | ||
result = hcpe['gameResult'] | ||
# gameResult -> 0: DRAW, 1: BLACK_WIN, 2: WHITE_WIN | ||
#if board.turn == gameResult - 1: | ||
# psv['game_result'] = 1 | ||
#elif board.turn == 2 - gameResult: | ||
# psv['game_result'] = -1 | ||
move_sum += 1 | ||
res[result] += 1 | ||
if score > s_max: | ||
s_max = score | ||
if score < s_min: | ||
s_min = score | ||
print ("'move_sum=" +str(move_sum) +",result=" +str(result) + ",move=" + move_csa + ",score=" + str(score)) | ||
print (board) | ||
|
||
if (board.turn) == 0: | ||
sen = "+" | ||
else: | ||
sen = "-" | ||
v = 1.0 / (1.0 + math.exp(-score * 0.0013226)) | ||
comment = f"v={v:.3f}," | ||
print (sen + move_csa + "," + comment) | ||
s_res = "%SENNICHITE" | ||
if result == 1: | ||
s_res = "%-ILLEGAL_ACTION" | ||
elif result == 2: | ||
s_res = "%+ILLEGAL_ACTION" | ||
print (s_res) | ||
print ("/") | ||
|
||
#psvs.tofile(args.psv) | ||
print ("'move_sum=" +str(move_sum) +",result=" +str(result) + ",move=" + move_csa + ",score=" + str(score)) | ||
print ("'res[0]=" +str(res[0]) +",[1]=" +str(res[1]) + ",[2]=" + str(res[2]) + ",s_max="+str(s_max)+",s_min"+str(s_min)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
GCT�̊w�K�Ɏg�p�����f�[�^�Z�b�g�����J | ||
https://tadaoyamaoka.hatenablog.com/entry/2021/05/06/223701 | ||
|
||
python3 ./hcpe3_to_csa.py --aoba --out_v --sort_visits selfplay_gct-051.hcpe3 dummy.csa >> selfplay_gct-051.csa | ||
|
||
����AI�̎����m�[�g�F����̕��z���w�K ���̂Q | ||
https://tadaoyamaoka.hatenablog.com/entry/2021/03/16/235251 | ||
���t�ǖʃt�H�[�}�b�g(hcpe) | ||
�ǖʒP�ʂɏo�͂��āA�s�v�ȋǖʁi���@�肪1�肵���Ȃ��ǖʁj�́A�o�͂��Ă��Ȃ������B | ||
�܂��A�ǂ̋��ڂ����m�ɂ킩��Ȃ� | ||
|
||
|
||
hcpe_to_csa.py �͈ȉ��̃f�B���N�g���ɒu���Ď��s | ||
|
||
$ python3 /home/yss/shogi/dlshogi_dr2_exhi/dlshogi/utils/hcpe_to_csa.py dlshogi_with_gct-024.hcpe > dlshogi_with_gct-024.csa | ||
|
||
��菟���A�̋ǖʂ� | ||
%-ILLEGAL_ACTION (��肪��������w�����̂Ő�菟��) | ||
��菟���A�̋ǖʂ� | ||
%+ILLEGAL_ACTION (��肪��������w�����̂Ō�菟��) | ||
�𗘗p�B | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
selfplay_gct-001.hcpe3 | ||
308133 ���� 3638986140 byte�ŁB | ||
308133 * 75 = 23,109,975 | ||
2300���������x�B����75����x�ŁA15���ǖʁB | ||
|
||
|
||
|
||
|
||
dlshogi_with_gct-001.hcpe , 356250760 byte | ||
'move_sum=9375020,'res[0]=215305,[1]=4828653,[2]=4331062,s_max=30000,s_min-30000 | ||
|
||
339MB�� 937���ǖʁA���łɃV���b�t������Ă���B�����ɖ߂��͍̂���B | ||
024 �܂�24�� | ||
9375020 * 24 = 225,000,480 2���ǖ� | ||
|
||
339 MB *24 = 8GB | ||
|
||
hcpe�ɂ͋ǖ�(���)�A���̎�A�]���l(-30000 <= v <= +30000),�nj���(0...���������A1...��菟���A2...��菟��) | ||
��4�̂݁B�萔�͂Ȃ��B | ||
���� | ||
4828653�� | ||
4331062�s | ||
215305�� | ||
------------- | ||
(4828653 + 215305/2) / 9375020 = 0.5265 ��菟��0.526�ł���قǍ����Ȃ��B | ||
|
||
|
||
suisho3kai-001.csa , 55417414 byte / 1458353 �ǖ� = 38 byte/�ǖʁB�Ֆʂ�32byte���B | ||
842825�� | ||
615528�s | ||
0�� | ||
------------- | ||
1458353 �ǖ�, 0.5779 ��菟����0.57�ō����B �]���l(-31996 <= v <= +31997)�B�͈͂��Ⴄ�ȁB | ||
24�� 1458353 * 24 = 35,000,472 �ǖ� | ||
|
||
floodgate_2019-2021_r3500-001.hcpe , 11078976 byte | ||
155969 �� | ||
125196 �s | ||
10387 �� | ||
----------- | ||
291552 �ǖ� 0.5527 �]���l(-32767 <= v <= +32767) �B������������ɔ͈͂��Ⴄ | ||
24�� 291552 * 24 = 6,997,248 �ǖ� | ||
|
||
|
||
���v | ||
225,000,480 dlshogi_with_gct | ||
35,000,472 suisho3kai | ||
6,997,248 floodgate_2019-2021_r3500 | ||
-------------------- | ||
266,998,200 2��6�疜�ǖʁB2021�N5��6���ł͖�6���B | ||
|
||
1�ǖ�100byte�Ƃ���25GB�B | ||
|
||
CSA�ɕϊ����ēǂݍ���A | ||
266998238 �ǖʁB��⑽���B | ||
76.9 * 128GB = 98GB���g�p�B | ||
|
||
|
||
139910027 ��菟�� | ||
121668247 ��菟�� | ||
5419964 �������� | ||
---------------------- | ||
266998238 ��菟�� (0.534) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.