Update app.py
Browse files
app.py
CHANGED
|
@@ -37,8 +37,8 @@ def visualize(df_pairwise: pd.DataFrame) -> Figure:
|
|
| 37 |
|
| 38 |
|
| 39 |
# https://gist.github.com/dustalov/41678b70c40ba5a55430fa5e77b121d9#file-bradley_terry-py
|
| 40 |
-
def bradley_terry(wins: npt.NDArray[np.
|
| 41 |
-
seed: int = 0, tolerance: float = 10e-6, limit: int = 20) -> npt.NDArray[np.
|
| 42 |
M = wins + .5 * ties
|
| 43 |
|
| 44 |
T = M.T + M
|
|
@@ -72,7 +72,7 @@ def bradley_terry(wins: npt.NDArray[np.int64], ties: npt.NDArray[np.int64],
|
|
| 72 |
|
| 73 |
|
| 74 |
def centrality(algorithm: Callable[[nx.DiGraph], Dict[int, float]],
|
| 75 |
-
wins: npt.NDArray[np.
|
| 76 |
A = wins + .5 * ties
|
| 77 |
|
| 78 |
G = nx.from_numpy_array(A, create_using=nx.DiGraph)
|
|
@@ -84,30 +84,30 @@ def centrality(algorithm: Callable[[nx.DiGraph], Dict[int, float]],
|
|
| 84 |
return p
|
| 85 |
|
| 86 |
|
| 87 |
-
def counting(wins: npt.NDArray[np.
|
| 88 |
-
seed: int = 0, tolerance: float = 10e-6, limit: int = 100) -> npt.NDArray[np.
|
| 89 |
M = wins + .5 * ties
|
| 90 |
|
| 91 |
-
return cast(npt.NDArray[np.
|
| 92 |
|
| 93 |
|
| 94 |
-
def eigen(wins: npt.NDArray[np.
|
| 95 |
-
seed: int = 0, tolerance: float = 10e-6, limit: int = 100) -> npt.NDArray[np.
|
| 96 |
algorithm = partial(nx.algorithms.eigenvector_centrality_numpy, max_iter=limit, tol=tolerance)
|
| 97 |
|
| 98 |
return centrality(algorithm, wins, ties)
|
| 99 |
|
| 100 |
|
| 101 |
-
def pagerank(wins: npt.NDArray[np.
|
| 102 |
-
seed: int = 0, tolerance: float = 10e-6, limit: int = 100) -> npt.NDArray[np.
|
| 103 |
algorithm = partial(nx.algorithms.pagerank, max_iter=limit, tol=tolerance)
|
| 104 |
|
| 105 |
return centrality(algorithm, wins, ties)
|
| 106 |
|
| 107 |
|
| 108 |
# https://gist.github.com/dustalov/41678b70c40ba5a55430fa5e77b121d9#file-newman-py
|
| 109 |
-
def newman(wins: npt.NDArray[np.
|
| 110 |
-
seed: int = 0, tolerance: float = 10e-6, limit: int = 20) -> npt.NDArray[np.
|
| 111 |
rng = np.random.default_rng(seed)
|
| 112 |
|
| 113 |
pi, v = rng.random(wins.shape[0]), rng.random()
|
|
@@ -214,8 +214,8 @@ def handler(file: IO[bytes], algorithm: str, filtered: bool, truncated: bool, se
|
|
| 214 |
aggfunc='count', fill_value=0)
|
| 215 |
df_ties = df_ties.reindex(labels=index, columns=index, fill_value=0, copy=False)
|
| 216 |
|
| 217 |
-
wins = df_wins.to_numpy(dtype=
|
| 218 |
-
ties = df_ties.to_numpy(dtype=
|
| 219 |
ties += ties.T
|
| 220 |
|
| 221 |
assert wins.shape == ties.shape, 'wins and ties shapes are different'
|
|
|
|
| 37 |
|
| 38 |
|
| 39 |
# https://gist.github.com/dustalov/41678b70c40ba5a55430fa5e77b121d9#file-bradley_terry-py
|
| 40 |
+
def bradley_terry(wins: npt.NDArray[np.int_], ties: npt.NDArray[np.int_],
|
| 41 |
+
seed: int = 0, tolerance: float = 10e-6, limit: int = 20) -> npt.NDArray[np.float_]:
|
| 42 |
M = wins + .5 * ties
|
| 43 |
|
| 44 |
T = M.T + M
|
|
|
|
| 72 |
|
| 73 |
|
| 74 |
def centrality(algorithm: Callable[[nx.DiGraph], Dict[int, float]],
|
| 75 |
+
wins: npt.NDArray[np.int_], ties: npt.NDArray[np.int_]) -> npt.NDArray[np.float_]:
|
| 76 |
A = wins + .5 * ties
|
| 77 |
|
| 78 |
G = nx.from_numpy_array(A, create_using=nx.DiGraph)
|
|
|
|
| 84 |
return p
|
| 85 |
|
| 86 |
|
| 87 |
+
def counting(wins: npt.NDArray[np.int_], ties: npt.NDArray[np.int_],
|
| 88 |
+
seed: int = 0, tolerance: float = 10e-6, limit: int = 100) -> npt.NDArray[np.float_]:
|
| 89 |
M = wins + .5 * ties
|
| 90 |
|
| 91 |
+
return cast(npt.NDArray[np.float_], M.sum(axis=1))
|
| 92 |
|
| 93 |
|
| 94 |
+
def eigen(wins: npt.NDArray[np.int_], ties: npt.NDArray[np.int_],
|
| 95 |
+
seed: int = 0, tolerance: float = 10e-6, limit: int = 100) -> npt.NDArray[np.float_]:
|
| 96 |
algorithm = partial(nx.algorithms.eigenvector_centrality_numpy, max_iter=limit, tol=tolerance)
|
| 97 |
|
| 98 |
return centrality(algorithm, wins, ties)
|
| 99 |
|
| 100 |
|
| 101 |
+
def pagerank(wins: npt.NDArray[np.int_], ties: npt.NDArray[np.int_],
|
| 102 |
+
seed: int = 0, tolerance: float = 10e-6, limit: int = 100) -> npt.NDArray[np.float_]:
|
| 103 |
algorithm = partial(nx.algorithms.pagerank, max_iter=limit, tol=tolerance)
|
| 104 |
|
| 105 |
return centrality(algorithm, wins, ties)
|
| 106 |
|
| 107 |
|
| 108 |
# https://gist.github.com/dustalov/41678b70c40ba5a55430fa5e77b121d9#file-newman-py
|
| 109 |
+
def newman(wins: npt.NDArray[np.int_], ties: npt.NDArray[np.int_],
|
| 110 |
+
seed: int = 0, tolerance: float = 10e-6, limit: int = 20) -> npt.NDArray[np.float_]:
|
| 111 |
rng = np.random.default_rng(seed)
|
| 112 |
|
| 113 |
pi, v = rng.random(wins.shape[0]), rng.random()
|
|
|
|
| 214 |
aggfunc='count', fill_value=0)
|
| 215 |
df_ties = df_ties.reindex(labels=index, columns=index, fill_value=0, copy=False)
|
| 216 |
|
| 217 |
+
wins = df_wins.to_numpy(dtype=int)
|
| 218 |
+
ties = df_ties.to_numpy(dtype=int)
|
| 219 |
ties += ties.T
|
| 220 |
|
| 221 |
assert wins.shape == ties.shape, 'wins and ties shapes are different'
|