TinaTz
TinaTz

Reputation: 311

What is the correct implementation of Katz index in python?

I am trying to implement Katz index using the following formula

alpha=0.01

G = nx.karate_club_graph()
A=nx.adjacency_matrix(G).todense()
n=A.shape[0]
I=np.eye(n,n)
result=np.linalg.inv(iden - (alpha * A))-I
print(np.round(result,6))

However I am not sure if this implementation is correct, because no iteration (path length is involved). I just directly code this formula inv((I − alpha*A)-I

Any help will be highly appreciated

Upvotes: 0

Views: 460

Answers (2)

J.Ayoub
J.Ayoub

Reputation: 51

I think that according to the katz metric line 5 should be:

result=np.linalg.inv(I - (alpha * A))-I

NB: In order to access the probability of link, for instance (3,4) because lists start from 0.

print("katz",link,"=",katz[link[0]-1,link[1]-1])

Upvotes: 1

shaho biniaz
shaho biniaz

Reputation: 1

NetworkX library in python uses a power method to implement the Katz index. you can compare result of your algorithm with that

Upvotes: 0

Related Questions