Skip to content

Instantly share code, notes, and snippets.

@TadaoYamaoka
Created May 6, 2021 11:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TadaoYamaoka/07c5ca2f067741b2f01613dfcada4895 to your computer and use it in GitHub Desktop.
Save TadaoYamaoka/07c5ca2f067741b2f01613dfcada4895 to your computer and use it in GitHub Desktop.
import argparse
from cshogi import *
import numpy as np
import pandas as pd
from scipy.optimize import curve_fit
parser = argparse.ArgumentParser()
parser.add_argument('hcpe')
args = parser.parse_args()
# 評価値から勝率への変換
def score_to_value(score, a):
return 1.0 / (1.0 + np.exp(-score / a))
hcpes = np.fromfile(args.hcpe, HuffmanCodedPosAndEval)
turns = hcpes['hcp'][:,0] & 1 # hcpの1ビット目はturnを表す
signs = 1 - turns.astype(np.int8) * 2 # 後手の符号を反転
df = pd.DataFrame({'score': hcpes['eval'] * signs, 'result': 2 - hcpes['gameResult']})
print(df['score'].describe())
print(df['result'].describe())
X = df['score']
Y = df['result']
popt, pcov = curve_fit(score_to_value, X, Y, p0=[600.0])
print(popt)
print('score < 1000')
df1 = df[df['score'].abs() < 1000]
X = df1['score']
Y = df1['result']
popt, pcov = curve_fit(score_to_value, X, Y, p0=[600.0])
print(popt)
print('score >= 1000')
df2 = df[df['score'].abs() >= 1000]
X = df2['score']
Y = df2['result']
popt, pcov = curve_fit(score_to_value, X, Y, p0=[600.0])
print(popt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment