summaryrefslogtreecommitdiff
path: root/rank.py
diff options
context:
space:
mode:
authorTuowen Zhao <ztuowen@gmail.com>2021-03-12 18:24:53 -0700
committerTuowen Zhao <ztuowen@gmail.com>2021-03-12 18:24:53 -0700
commitbe4bd00c998fc0c103aaaf682d85c71a2073ce71 (patch)
tree48d004013c0618f06f31376b3bbe6173b8837338 /rank.py
parent883de2e9e78045fb32d3fd256707a895894610ed (diff)
downloadlpl-be4bd00c998fc0c103aaaf682d85c71a2073ce71.tar.gz
lpl-be4bd00c998fc0c103aaaf682d85c71a2073ce71.tar.bz2
lpl-be4bd00c998fc0c103aaaf682d85c71a2073ce71.zip
Add smooth & score functions
Diffstat (limited to 'rank.py')
-rw-r--r--rank.py50
1 files changed, 37 insertions, 13 deletions
diff --git a/rank.py b/rank.py
index c38ad76..26cbaee 100644
--- a/rank.py
+++ b/rank.py
@@ -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)