From be4bd00c998fc0c103aaaf682d85c71a2073ce71 Mon Sep 17 00:00:00 2001
From: Tuowen Zhao <ztuowen@gmail.com>
Date: Fri, 12 Mar 2021 18:24:53 -0700
Subject: Add smooth & score functions

---
 rank.py | 50 +++++++++++++++++++++++++++++++++++++-------------
 1 file 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)
-- 
cgit v1.2.3-70-g09d2