def adjacency_to_google ( A ): #*****************************************************************************80 # ## adjacency_to_google() converts an adjacency matrix to a Google transition matrix. # # Discussion: # # If the input adjacency matrix has a node I with no connectivity, # (A(I,1:N) = 0) then we artificially set T(1:N,I)=1/N, so that # the transition matrix property of having unit column sums is preserved. # # For nodes with connectivity, we assume that 85 percent of the time # we will take a link at random, and 15 percent of the time, we will # jump to an arbitrary link. # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 12 February 2025 # # Author: # # John Burkardt # # Input: # # integer A(N,N): the adjacency matrix. # # Output: # # real G(N,N): the Google matrix. # import numpy as np n = A.shape[0] G = np.zeros ( [ n, n ] ) s = np.sum ( A, axis = 1 ) for i in range ( 0, n ): if ( s[i] == 0.0 ): G[i,:] = 1.0 / n else: G[i,:] = 0.85 * A[i,:] / s[i] + 0.15 / n G = np.transpose ( G ) return G