<jupyter_start><jupyter_text>PAGERANK ALGORITHM<jupyter_code>import matplotlib.pyplot as plt
import networkx as nx
import numpy as np
N= 5     #Number of Nodes or web pages
q= 0.85     # Damping factor (coefficient de calibrage) 
G= nx.gnp_random_graph(N,0.6,seed=None, directed=True) # generate random directed graph
# visualize graph
pos = nx.spring_layout(G)
nx.draw_networkx_nodes(G,pos,node_size=500)
nx.draw_networkx_edges(G, pos, edgelist=G.edges(),edge_color='black')
nx.draw_networkx_labels(G, pos)
plt.show()
A = nx.to_numpy_matrix(G) #Convert Graph to Adjacency matrix
print(A)
#Lines contains where the node is pointing
#Row contains the nodes that are pointing the the n node
#Simplified transition matrix Function
def STMF(x):
    return x/x.sum(axis=1)
STM = STMF(A)
print(STM)
#Non-Simplified transition matrix Function
def NSTMF(x):
    A = STMF(x)
    AT = A*q+((1-q)/N)
    return AT
NSTM = NSTMF(A)
print(NSTM)
#Simplified PageRank Vector
PRSTM =np.sum(STM,axis=0)  
print(PRSTM)
#Non-Simplified PageRank Vector
PRNSTM =np.sum(NSTM,axis=0)  
print(PRNSTM)<jupyter_output>[[0.85833333 0.85833333 0.7875     1.49583333 1.        ]]
{'fraction_non_alphanumeric': 0.11401218450826806, 'fraction_numerical': 0.04003481288076589, 'mean_word_length': 5.117021276595745, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '280785', 'license': 'MIT', 'n_tokens_mistral': 481, 'n_tokens_neox': 449, 'n_words': 114, 'path': 'PageRank.ipynb', 'repo_name': 'Mouheb97/Web-Search-algorithms', 'size': '1149'}