Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Wed Oct 23 08:11:37 2019
  4.  
  5. @author: Gloomy
  6. """
  7.  
  8.  
  9. import numpy as np
  10. import math
  11.  
  12. def Koczkodaj(matrix):
  13.  
  14. maxval = 0;
  15. for i in range(len(matrix)):
  16. for j in range(len(matrix)):
  17. if i == j:
  18. continue
  19. for k in range(len(matrix)):
  20. if j == k:
  21. continue
  22. kocz = min(abs(1-(matrix[i][k]*matrix[k][j])/matrix[i][j]),abs(1-matrix[i][j]/(matrix[i][k]*matrix[k][j])) )
  23. if kocz > maxval:
  24. maxval = kocz
  25. return maxval;
  26.  
  27. def KoczkodajThreshold(n,k):
  28. return 1-((1+ math.sqrt(4*(n-1)*(n-k-2)))/(2*(n-1)))
  29.  
  30. def HREknown(Comp, knownIndexes, knownVals):
  31. kocz = Koczkodaj(Comp)
  32.  
  33. print("Koczkodaj's index: {0}".format(kocz))
  34. if kocz < KoczkodajThreshold(len(Comp),len(knownIndexes)):
  35. print("Koczkodaj passes")
  36. else:
  37. print("Koczkodaj fails")
  38.  
  39. knownSize = len(knownIndexes)
  40. unknownSize = len(Comp) - len(knownIndexes)
  41.  
  42. unknownIndexes = list(range(len(Comp)))
  43. for index in knownIndexes:
  44. unknownIndexes.remove(index)
  45.  
  46. A = np.ndarray.tolist(np.zeros([unknownSize,unknownSize]))
  47. B = np.ndarray.tolist(np.zeros([unknownSize,knownSize]))
  48.  
  49. for i in range(unknownSize):
  50. for j in range(unknownSize):
  51. x = 1
  52. if i != j:
  53. x = (-1/(len(Comp)-1))
  54. A[i][j] = x* Comp[unknownIndexes[i]][unknownIndexes[j]]
  55.  
  56. for i in range(unknownSize):
  57. for j in range(knownSize):
  58. B[i][j] = Comp[unknownIndexes[i]][knownIndexes[j]]
  59.  
  60. Bhat = np.ndarray.tolist(np.matmul(B,knownVals))
  61. Bhat = np.matmul(1/(len(Comp)-1)*np.identity(len(Bhat)),Bhat)
  62.  
  63. result = np.ndarray.tolist(np.linalg.solve(A,Bhat))
  64.  
  65. return result
  66.  
  67. A=[[ 1,2/3,2,5/2,5/3,5],[
  68. 3/2,1,3,10/3,3,9],[
  69. 1/2,1/3,1,4/3,7/8,5/2],[
  70. 2/5,3/10,3/4,1,5/6,12/5],[
  71. 3/5,1/3,8/7,6/5,1,3],[
  72. 1/5,1/9,2/5,5/12,1/3,1]]
  73.  
  74. AknownIndexes = [4,5]
  75. AknownVals = [3,1]
  76.  
  77. B=[[1,2/5,3,7/3,1/2,1],[
  78. 5/2,1,4/7,5/8,1/3,3],[
  79. 1/3,7/4,1,1/2,2,1/2],[
  80. 3/7,8/5,2,1,4,2],[
  81. 2,3,1/2,1/4,1,1/2],[
  82. 1,1/3,2,1/2,2,1]]
  83.  
  84. BknownIndexes = [3,4,5]
  85. BknownVals = [2,1/2,1]
  86.  
  87.  
  88. C=[[1,17/4,17/20,8/5,23/6,8/3],[
  89. 4/17,1,1/5,2/5,9/10,2/3],[
  90. 20/17,5,1,21/10,51/10,10/3],[
  91. 5/8,5/2,10/21,1,5/2,11/6],[
  92. 6/23,10/9,10/51,2/5,1,19/30],[
  93. 3/8,3/2,3/10,6/11,30/19,1]]
  94.  
  95.  
  96. CknownIndexes = [1,3]
  97. CknownVals = [2,5]
  98.  
  99. Aresult = HREknown(A,AknownIndexes,AknownVals)
  100.  
  101. print("final rating HRE matrix A:\n {0}".format(Aresult))
  102.  
  103. Bresult = HREknown(B,BknownIndexes,BknownVals)
  104.  
  105. print("final rating HRE matrix B:\n {0}".format(Bresult))
  106.  
  107. Cresult = HREknown(C,CknownIndexes,CknownVals)
  108.  
  109. print("final rating HRE matrix C:\n {0}".format(Cresult))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement