Other small final fixes

main
Luca Lombardo 2 years ago
parent 378fa96686
commit b4aed0d684

@ -420,7 +420,7 @@ def pagerank(G, alpha=0.85, personalization=None, max_iter=10000, tol=1.0e-9, ns
x = alpha * (x @ A + sum(x[is_dangling]) * dangling_weights) + (1 - alpha) * p # x is the current vector of PageRank values x = alpha * (x @ A + sum(x[is_dangling]) * dangling_weights) + (1 - alpha) * p # x is the current vector of PageRank values
# check convergence, l1 norm # check convergence, l1 norm
err = np.absolute(x - xlast).sum() # err is the error between the current and previous vectors of PageRank values err = np.absolute(x - xlast).sum() # err is the error between the current and previous vectors of PageRank values
print("Iteration: ", _, "\r", end="") # print("Iteration: ", _, "\r", end="")
if err < N * tol: # if the error is small enough, stop iterating if err < N * tol: # if the error is small enough, stop iterating
return dict(zip(nodelist, map(float, x))), iter, tol # return the current vector of PageRank values' return dict(zip(nodelist, map(float, x))), iter, tol # return the current vector of PageRank values'
@ -508,8 +508,7 @@ def shifted_pow_pagerank(G, alphas=[0.85, 0.9, 0.95, 0.99], max_iter=10000, tol=
print("Convergence reached with, ", mv, " matrix-vector multiplications") print("Convergence reached with, ", mv, " matrix-vector multiplications")
return x, mv, alphas, tol return x, mv, alphas, tol
print("Iteration: ", _, "\r", end="") # print("Iteration: ", _, "\r", end="")
mu = A @ mu mu = A @ mu
mv += 1 mv += 1

@ -8,7 +8,7 @@ warnings.filterwarnings("ignore")
# df = pd.DataFrame(columns=["method" "alpha", "cpu_time", "mv", "tol"]) # df = pd.DataFrame(columns=["method" "alpha", "cpu_time", "mv", "tol"])
def run_standard_pagerank(G, alphas): def run_standard_pagerank(G, alphas):
print("\nStarting the standard pagerank algorithm...\n") print("\nStarting the standard pagerank algorithm...")
iter_dict = dict.fromkeys(alphas, 0) iter_dict = dict.fromkeys(alphas, 0)
list_of_pageranks = [] list_of_pageranks = []
@ -24,10 +24,10 @@ def run_standard_pagerank(G, alphas):
cpu_time = round(end1 - start1,1) cpu_time = round(end1 - start1,1)
mv = total_iter mv = total_iter
print("\nSTANDARD PAGERANK ALGORITHM\n") print("\nSTANDARD PAGERANK ALGORITHM RESULTS:\n")
print("\tCPU time (s):", cpu_time) print("\tCPU time (s):", cpu_time)
print("\tMatrix-vector multiplications:", mv) print("\tMatrix-vector multiplications:", mv)
print("\tAlpha:", alphas) print("\tAlpha(s):", alphas)
print("\tTolerance:", tol) print("\tTolerance:", tol)
for i in range(len(list_of_pageranks)): for i in range(len(list_of_pageranks)):
@ -41,17 +41,17 @@ def run_standard_pagerank(G, alphas):
def run_shifted_powe(G, alphas): def run_shifted_powe(G, alphas):
print("\nStarting the SHIFTED PAGERANK ALGORITHM...\n") print("\nStarting the shifted power method... (this may take a while)")
start2 = time.time() start2 = time.time()
x, mv, alphas, tol = shifted_pow_pagerank(G, alphas, tol=1e-6) x, mv, alphas, tol = shifted_pow_pagerank(G, alphas, tol=1e-6)
end2 = time.time() end2 = time.time()
cpu_time = round(end2 - start2,1) cpu_time = round(end2 - start2,1)
print("\nSHIFTED PAGERANK ALGORITHM\n") print("\nSHIFTED PAGERANK ALGORITHM RESULTS:\n")
print("\tCPU time (s):", cpu_time) print("\tCPU time (s):", cpu_time)
print("\tMatrix-vector multiplications:", mv) print("\tMatrix-vector multiplications:", mv)
print("\tAlphas:", alphas) print("\tAlphas(s):", alphas)
print("\tTolerance:", tol) print("\tTolerance:", tol)
# df.loc[len(df)] = ["Shifted Power Method", alphas, cpu_time, mv, tol] # df.loc[len(df)] = ["Shifted Power Method", alphas, cpu_time, mv, tol]

Loading…
Cancel
Save