diff options
Diffstat (limited to 'rank.py')
-rw-r--r-- | rank.py | 50 |
1 files changed, 37 insertions, 13 deletions
@@ -146,38 +146,62 @@ for idx, name in enumerate(teams): team_fac = [0] * len(teams) team_cnt = [0] * len(teams) -# choices of different smoothing function -def naive(team, weight): + +def smooth_naive(team, weight): return weight -def exp(team, weight): + +def smooth_exp(team, weight): N = 5 return math.exp(-team_cnt[team]/N) * weight -def normal(team, weight): + +def smooth_normal(team, weight): N = 5 return math.exp(-((team_cnt[team]/N)**2)) * weight -def shock(team, weight): + +def smooth_shock(team, weight): N = 5 if team_cnt[team] < N: return weight else: return 0 -filter_func = shock + +def score_naive(a, b): + return a + + +def score_fivefive(a, b): + return 1 if a > 0 else 0 + + +def score_avg(a, b): + total = a + b + return a / total + + +def score_takeall(a, b): + return 1 if a > b else 0 + + +# choose a smoothing function (naive, exp, normal, shock) +smooth_func = smooth_naive + +# choose a score function (naive, fivefive, avgscore, takeall) +score_func = score_naive for match in reversed(matches): l = team_dict[match[0]] r = team_dict[match[1]] # Normalize each match - tot = match[2] + match[3] - w = filter_func(r, match[2] / tot) + w = smooth_func(r, score_func(match[2], match[3])) team_fac[r] += w match_matrix[l].append([r, w]) - w = filter_func(l, match[3] / tot) + w = smooth_func(l, score_func(match[3], match[2])) team_fac[l] += w match_matrix[r].append([l, w]) team_cnt[l] += 1 @@ -212,8 +236,9 @@ for idx, name in enumerate(teams): team_rank.sort(key=lambda x: x[1], reverse=True) -# Tier list using K-mean -K = 4 # S A B C +# Tier list using K-means +K = 4 +rank_name = ["S", "A", "B", "C", "D", "E", "F"] means = [0] * K for i in range(K): means[i] = team_rank[i * len(teams)//K][1] @@ -235,7 +260,6 @@ for i in range(1000): means[k] = tot[k] / cnt[k] print("Result of k-means") -rank_name = ["S", "A", "B", "C"] for idx, m in enumerate(means): print("\t", rank_name[idx], m) @@ -246,4 +270,4 @@ for rank in team_rank: if abs(m - rank[1]) < dist: bidx = idx dist = abs(m - rank[1]) - print(rank_name[bidx], rank)
\ No newline at end of file + print(rank_name[bidx], rank) |