Add PageRank
Browse files- app.py +16 -1
- requirements.txt +1 -0
app.py
CHANGED
@@ -15,9 +15,10 @@
|
|
15 |
__author__ = 'Dmitry Ustalov'
|
16 |
__license__ = 'Apache 2.0'
|
17 |
|
18 |
-
from typing import IO, Tuple, List, cast
|
19 |
|
20 |
import gradio as gr
|
|
|
21 |
import numpy as np
|
22 |
import numpy.typing as npt
|
23 |
import pandas as pd
|
@@ -67,6 +68,19 @@ def bradley_terry(wins: npt.NDArray[np.int64], ties: npt.NDArray[np.int64],
|
|
67 |
return p
|
68 |
|
69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
# https://gist.github.com/dustalov/41678b70c40ba5a55430fa5e77b121d9#file-newman-py
|
71 |
def newman(wins: npt.NDArray[np.int64], ties: npt.NDArray[np.int64],
|
72 |
seed: int = 0, tolerance: float = 10e-6, limit: int = 20) -> npt.NDArray[np.float64]:
|
@@ -117,6 +131,7 @@ def newman(wins: npt.NDArray[np.int64], ties: npt.NDArray[np.int64],
|
|
117 |
|
118 |
ALGORITHMS = {
|
119 |
'Bradley-Terry (1952)': bradley_terry,
|
|
|
120 |
'Newman (2023)': newman,
|
121 |
}
|
122 |
|
|
|
15 |
__author__ = 'Dmitry Ustalov'
|
16 |
__license__ = 'Apache 2.0'
|
17 |
|
18 |
+
from typing import IO, Tuple, List, cast, Dict
|
19 |
|
20 |
import gradio as gr
|
21 |
+
import networkx as nx
|
22 |
import numpy as np
|
23 |
import numpy.typing as npt
|
24 |
import pandas as pd
|
|
|
68 |
return p
|
69 |
|
70 |
|
71 |
+
def pagerank(wins: npt.NDArray[np.int64], ties: npt.NDArray[np.int64],
|
72 |
+
seed: int = 0, tolerance: float = 10e-6, limit: int = 100) -> npt.NDArray[np.float64]:
|
73 |
+
A = wins + .5 * ties
|
74 |
+
|
75 |
+
G = nx.from_numpy_array(A, create_using=nx.DiGraph)
|
76 |
+
|
77 |
+
pagerank: Dict[int, float] = nx.algorithms.pagerank(G, max_iter=limit, tol=tolerance)
|
78 |
+
|
79 |
+
scores = np.array([pagerank[i] for i in range(len(G))])
|
80 |
+
|
81 |
+
return scores
|
82 |
+
|
83 |
+
|
84 |
# https://gist.github.com/dustalov/41678b70c40ba5a55430fa5e77b121d9#file-newman-py
|
85 |
def newman(wins: npt.NDArray[np.int64], ties: npt.NDArray[np.int64],
|
86 |
seed: int = 0, tolerance: float = 10e-6, limit: int = 20) -> npt.NDArray[np.float64]:
|
|
|
131 |
|
132 |
ALGORITHMS = {
|
133 |
'Bradley-Terry (1952)': bradley_terry,
|
134 |
+
'PageRank': pagerank,
|
135 |
'Newman (2023)': newman,
|
136 |
}
|
137 |
|
requirements.txt
CHANGED
@@ -1 +1,2 @@
|
|
|
|
1 |
plotly_express
|
|
|
1 |
+
networkx
|
2 |
plotly_express
|