Advertisement
Guest User

Untitled

a guest
Oct 10th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.03 KB | None | 0 0
  1. import numpy as np
  2. import math as m
  3.  
  4. C1 = np.array([[1, 1 / 7, 1 / 5],
  5.                [7, 1, 3],
  6.                [5, 1 / 3, 1]])
  7.  
  8. C2 = np.array([[1, 5, 9],
  9.                [1 / 5, 1, 4],
  10.                [1 / 9, 1 / 4, 1]])
  11.  
  12. C3 = np.array([[1, 4, 1 / 5],
  13.                [1 / 4, 1, 1 / 9],
  14.                [5, 1 / 3, 1]])
  15. C4 = np.array([[1, 9, 4],
  16.                [1 / 9, 1, 1 / 4],
  17.                [1 / 4, 4, 1]])
  18. C5 = np.array([[1, 1, 1],
  19.                [1, 1, 1],
  20.                [1, 1, 1]])
  21. C6 = np.array([[1, 6, 4],
  22.                [1 / 6, 1, 1 / 3],
  23.                [1 / 4, 3, 1]])
  24. C7 = np.array([[1, 9, 6],
  25.                [1 / 9, 1, 1 / 3],
  26.                [1 / 6, 3, 1]])
  27. C8 = np.array([[1, 1 / 2, 1 / 2],
  28.                [2, 1, 1],
  29.                [2, 1, 1]])
  30.  
  31. list_C = [C1, C2, C3, C4, C5, C6, C7, C8]
  32.  
  33. wektory_wlasne = []
  34. for c in list_C:
  35.     w, v = np.linalg.eig(c)
  36.     w1, w2, w3 = w
  37.     v1, v2, v3 = v
  38.  
  39.     if not np.isreal(w1):
  40.         w1 = -m.inf
  41.     if not np.isreal(w2):
  42.         w2 = -m.inf
  43.     if not np.isreal(w3):
  44.         w3 = -m.inf
  45.  
  46.     values = [np.real(w1), np.real(w2), np.real(w3)]
  47.     i = values.index(max(values))
  48.     wektory_wlasne.append(np.real(v[:, i]))
  49.  
  50. for wektor in wektory_wlasne:
  51.     suma = sum(wektor)
  52.     wektor[0] = wektor[0] / suma
  53.     wektor[1] = wektor[1] / suma
  54.     wektor[2] = wektor[2] / suma
  55.  
  56.  
  57. Wec = np.transpose(np.array(wektory_wlasne))
  58.  
  59.  
  60. X = np.array([[1.0, 4.0, 7.0, 5.0, 8.0, 6.0, 6.0, 2.0],
  61.               [1 / 4, 1.0, 5.0, 3.0, 7.0, 6.0, 6.0, 1 / 3],
  62.               [1 / 7, 1 / 5, 1.0, 1 / 3, 5.0, 3.0, 3.0, 1 / 5],
  63.               [1 / 5, 1 / 3, 3, 1, 6.0, 3.0, 4.0, 1 / 2],
  64.               [1 / 8, 1 / 7, 1 / 5, 1 / 6, 1.0, 1 / 3, 1 / 4, 1 / 7],
  65.               [1 / 6, 1 / 6, 1 / 3, 1 / 3, 3.0, 1.0, 1 / 2, 1 / 5],
  66.               [1 / 6, 1 / 6, 1 / 3, 1 / 4, 4.0, 2.0, 1.0, 1 / 5],
  67.               [1 / 2, 3.0, 5.0, 2.0, 7.0, 5.0, 5.0, 1.0]])
  68.  
  69. result = Wec.dot(X)
  70.  
  71. print('Result 1: ', sum(result[0]))
  72. print('Result 2: ', sum(result[1]))
  73. print('Result 3: ', sum(result[2]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement