Update app.py
Browse files
app.py
CHANGED
@@ -38,8 +38,8 @@ def visualize(df_pairwise: pd.DataFrame) -> Figure:
|
|
38 |
|
39 |
|
40 |
# https://gist.github.com/dustalov/41678b70c40ba5a55430fa5e77b121d9#file-bradley_terry-py
|
41 |
-
def bradley_terry(wins: npt.NDArray[np.
|
42 |
-
seed: int = 0, tolerance: float = 10e-6, limit: int = 20) -> npt.NDArray[np.
|
43 |
M = wins + .5 * ties
|
44 |
|
45 |
T = M.T + M
|
@@ -73,7 +73,7 @@ def bradley_terry(wins: npt.NDArray[np.int_], ties: npt.NDArray[np.int_],
|
|
73 |
|
74 |
|
75 |
def centrality(algorithm: Callable[[nx.DiGraph], dict[int, float]],
|
76 |
-
wins: npt.NDArray[np.
|
77 |
A = wins + .5 * ties
|
78 |
|
79 |
G = nx.from_numpy_array(A, create_using=nx.DiGraph)
|
@@ -85,33 +85,31 @@ def centrality(algorithm: Callable[[nx.DiGraph], dict[int, float]],
|
|
85 |
return p
|
86 |
|
87 |
|
88 |
-
def counting(wins: npt.NDArray[np.
|
89 |
-
seed: int = 0, tolerance: float = 10e-6, limit: int = 100) -> npt.NDArray[np.
|
90 |
M = wins + .5 * ties
|
91 |
|
92 |
-
return cast(npt.NDArray[np.
|
93 |
|
94 |
|
95 |
-
def eigen(wins: npt.NDArray[np.
|
96 |
-
seed: int = 0, tolerance: float = 10e-6, limit: int = 100) -> npt.NDArray[np.
|
97 |
algorithm = partial(nx.algorithms.eigenvector_centrality_numpy, max_iter=limit, tol=tolerance)
|
98 |
|
99 |
return centrality(algorithm, wins, ties)
|
100 |
|
101 |
|
102 |
-
def pagerank(wins: npt.NDArray[np.
|
103 |
-
seed: int = 0, tolerance: float = 10e-6, limit: int = 100) -> npt.NDArray[np.
|
104 |
algorithm = partial(nx.algorithms.pagerank, max_iter=limit, tol=tolerance)
|
105 |
|
106 |
return centrality(algorithm, wins, ties)
|
107 |
|
108 |
|
109 |
# https://gist.github.com/dustalov/41678b70c40ba5a55430fa5e77b121d9#file-newman-py
|
110 |
-
def newman(wins: npt.NDArray[np.
|
111 |
-
seed: int = 0, tolerance: float = 10e-6, limit: int = 20) -> npt.NDArray[np.
|
112 |
-
|
113 |
-
|
114 |
-
pi, v = rng.random(wins.shape[0]), rng.random()
|
115 |
|
116 |
converged, iterations = False, 0
|
117 |
|
|
|
38 |
|
39 |
|
40 |
# https://gist.github.com/dustalov/41678b70c40ba5a55430fa5e77b121d9#file-bradley_terry-py
|
41 |
+
def bradley_terry(wins: npt.NDArray[np.int64], ties: npt.NDArray[np.int64],
|
42 |
+
seed: int = 0, tolerance: float = 10e-6, limit: int = 20) -> npt.NDArray[np.float64]:
|
43 |
M = wins + .5 * ties
|
44 |
|
45 |
T = M.T + M
|
|
|
73 |
|
74 |
|
75 |
def centrality(algorithm: Callable[[nx.DiGraph], dict[int, float]],
|
76 |
+
wins: npt.NDArray[np.int64], ties: npt.NDArray[np.int64]) -> npt.NDArray[np.float64]:
|
77 |
A = wins + .5 * ties
|
78 |
|
79 |
G = nx.from_numpy_array(A, create_using=nx.DiGraph)
|
|
|
85 |
return p
|
86 |
|
87 |
|
88 |
+
def counting(wins: npt.NDArray[np.int64], ties: npt.NDArray[np.int64],
|
89 |
+
seed: int = 0, tolerance: float = 10e-6, limit: int = 100) -> npt.NDArray[np.float64]:
|
90 |
M = wins + .5 * ties
|
91 |
|
92 |
+
return cast(npt.NDArray[np.float64], M.sum(axis=1))
|
93 |
|
94 |
|
95 |
+
def eigen(wins: npt.NDArray[np.int64], ties: npt.NDArray[np.int64],
|
96 |
+
seed: int = 0, tolerance: float = 10e-6, limit: int = 100) -> npt.NDArray[np.float64]:
|
97 |
algorithm = partial(nx.algorithms.eigenvector_centrality_numpy, max_iter=limit, tol=tolerance)
|
98 |
|
99 |
return centrality(algorithm, wins, ties)
|
100 |
|
101 |
|
102 |
+
def pagerank(wins: npt.NDArray[np.int64], ties: npt.NDArray[np.int64],
|
103 |
+
seed: int = 0, tolerance: float = 10e-6, limit: int = 100) -> npt.NDArray[np.float64]:
|
104 |
algorithm = partial(nx.algorithms.pagerank, max_iter=limit, tol=tolerance)
|
105 |
|
106 |
return centrality(algorithm, wins, ties)
|
107 |
|
108 |
|
109 |
# https://gist.github.com/dustalov/41678b70c40ba5a55430fa5e77b121d9#file-newman-py
|
110 |
+
def newman(wins: npt.NDArray[np.int64], ties: npt.NDArray[np.int64],
|
111 |
+
seed: int = 0, tolerance: float = 10e-6, limit: int = 20) -> npt.NDArray[np.float64]:
|
112 |
+
pi, v = np.ones(wins.shape[0]), .5
|
|
|
|
|
113 |
|
114 |
converged, iterations = False, 0
|
115 |
|