pids2 = replays.playerid2.astype(np.int) scores12 = (replays.score1 - replays.score2).astype(np.int) ratings = np.empty((nplayers,2),dtype=np.float) ub = np.array([1500., 500., 500., 50., 0.1]) lb = np.array([1500., 500., 50., 1., 0.01]) N=100000 results = np.zeros((N,6),dtype=np.double) * np.nan for n in range(N): print n, '\r', env = np.random.uniform(0.,1.,5) env *= ub-lb env += lb ratings[:,0] = env[0] ratings[:,1] = env[1] r1,r2,nGames1,nGames2,L = ts.rate_1vs1(env,pids1,pids2,scores12,ratings) idx = (nGames1>10) & (nGames2>10) L = np.sum(np.log(L[idx])) results[n,0:-1] = env results[n,-1] = L if n%100 == 99: save_results(results, 'learntrueskill_solution_space.txt') save_results(results, 'learntrueskill_solution_space.txt') env = results[-1,0:5] ratings[:,0] = env[0] ratings[:,1] = env[1] r1,r2,nGames1,nGames2,L = ts.rate_1vs1(env,pids1,pids2,scores12,ratings)
def eval_pyts(env, pid1, pid2, scores): nplayers = 1 + max(np.max(pid1), np.max(pid2)) ratings = np.zeros((nplayers, 2), dtype=np.float) ratings[:, 0] = env[0] ratings[:, 1] = env[1] return pyts.rate_1vs1(env, pid1, pid2, scores, ratings) + (ratings, )
nPlayersExamine = 5 figs_progression = [plt.subplots() for n in range(nPlayersExamine)] fig_filenames = {} probabilities = [[] for n in range(nPlayersExamine)] all_probabilities = [] aliases = [None for n in range(nPlayersExamine)] environments = (np.array([1500., 500., 250., 5., 0.1]), np.array([1500., 500., 240., 10., 0.045]), np.array([1500., 500., 240., 18., 0.045])) for nenv, env in enumerate(environments): ratings[:, 0] = env[0] ratings[:, 1] = env[1] r1, r2, nGames1, nGames2, L = ts.rate_1vs1(env, pids1, pids2, scores12, ratings) all_probabilities += [L] finalGameCount = np.zeros(nplayers, dtype=np.int) finalGameCount[pids1] = nGames1 iSorNGames = np.argsort(finalGameCount)[::-1] for nplayer, ((f1, ax1), PID) in enumerate(zip(figs_progression, iSorNGames)): idx1 = pids1 == PID idx2 = pids2 == PID aliases[nplayer] = ','.join(playerAliases[PID][1:]) mu = idx1 * r1[:, 0] + idx2 * r2[:, 0] sigma = idx1 * r1[:, 1] + idx2 * r2[:, 1] mu = mu[idx1 | idx2] sigma = sigma[idx1 | idx2]
def eval_pyts(env,pid1,pid2,scores): nplayers = 1+max(np.max(pid1),np.max(pid2)) ratings = np.zeros((nplayers,2),dtype=np.float) ratings[:,0] = env[0] ratings[:,1] = env[1] return pyts.rate_1vs1(env,pid1,pid2,scores,ratings) + (ratings,)