-
Notifications
You must be signed in to change notification settings - Fork 0
/
eigentrust.py
65 lines (43 loc) · 1.16 KB
/
eigentrust.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import numpy as np
Dimension = 50
#random matrix with local trust values
B =np.random.randint(5, size=(Dimension, Dimension))
print(B)
normalised_matrix = np.identity(Dimension)
print(normalised_matrix)
#normalising trust values
#getting rid of negatives
for i in range(len(B)):
for j in range(len(B)):
value = max( B[i,j], 0)
B[i,j] = value
#sum over j of S_ij
sum = B.sum(axis=1)
for i in range(len(B)):
for j in range(len(B)):
Sij = B[i,j]
sum_Sij = sum[i]
if (sum_Sij == 0):
normalised_matrix[i,j] = 0 #could replace this value with pre-trusted value
else:
normalised_matrix[i,j]= Sij/sum_Sij
#print(normalised_matrix)
#aggregating local trust values
#simple non-distributed eigentrust algorithm
#create e vector
e = np.empty(Dimension)
e.fill(1/Dimension)
e = np.matrix(e)
print(e)
#begin iterations
delta = 1
t = e.T
Ct = normalised_matrix.T
while (delta > 0.001):
t_2 = np.dot(Ct,t)
delta = np.linalg.norm(t_2-t)
t = t_2
#final global trust values https://dl.acm.org/doi/pdf/10.1145/775152.775242
print(t)
print(delta)
print(t.sum(axis=0))