• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Oct 21st, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. import numpy as np
2. import numpy.linalg as npl
3. import math
4.
5. def Satty(A):
6.     val, vec = npl.eig(A)
7.     real = np.isreal(val)
8.     for i in range (val.size):
9.         val[i] = 0 if real[i] is False else val[i]
10.     max = np.real(np.max(val))
11.     return (max-len(A))/(len(A)-1)
12.
13.
14. def Saaty(matrix, dim):
15.     w,v = npl.eig(matrix)
16.     eig_val = float(w.max())
17.     CI = (eig_val-dim)/(dim-1)
18.     return CI
19.
20.
21. # def getVec(A):
22. #     A=np.asarray(A)
23. #     result=[0]*len(A)
24. #     for i in range(len(A)):
25. #         result[i] = A[i].prod()**(1.0/len(A[i]))
26. #     result = result/np.sum(result)
27. #     result = np.transpose(result)
28. #     return result
29.
30.
31. def getRanking(A):
32.     result = []
33.     for W in A:
34.         W = np.squeeze(np.asarray(W))
35.         result.append(W.prod() ** (1.0 / len(W)))
36.     result = abs(np.asarray(result)) / sum(abs(np.asarray(result)))
37.     return result
38.
39.
40. def geom(A):
41.     ranking = getRanking(A)
42.     n = len(A)
43.     sum = 0
44.     for i in range(1, n):
45.         for j in range(i+1, n):
46.             sum += (math.log(A[i][j] * ranking[j]/ranking[i], 10)) ** 2
47.     return (2/((n-1)*(n-2)))*sum
48.
49.
50. def K(A,i,j,k):
51.   a=abs(1-(A[i][k]*A[k][j])/A[i][j])
52.   b=abs(1-A[i][j]/(A[i][k]*A[k][j]))
53.   return(min(a,b))
54.
55.
56. def Koczkodaj(A):
57.   max = 0
58.   for i in range (len(A)):
59.     for j in range (len(A)):
60.       for k in range (len(A)):
61.         if(K(A,i,j,k)>max):
62.           max = K(A,i,j,k)
63.   return max
64.
65. A=[[1,7,3] , [1/7,1,2] , [1/3,1/2,1]]
66. B=[[1,1/5,7,1] , [5,1,1/2,2] , [1/7,2,1,3] , [1,1/2,1/3,1]]
67. C=[[1,2,5,1,7] , [1/2,1,3,1/2,5] , [1/5,1/3,1,1/5,2] , [1,2,5,1,7] , [1/7,1/5,1/2,1/7,1]]
68.
69. print("Indeks Sattego:")
70. print(Satty(A))
71. print(Satty(B))
72. print(Satty(C))
73. print("Indeks Koczkodaja:")
74. print(Koczkodaj(A))
75. print(Koczkodaj(B))
76. print(Koczkodaj(C))
77. print("Indeks geometryczny")
78. print(geom(A))
79. print(geom(B))
80. print(geom(C))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top