
Лабораторная работа №3 - Азалия
.docximport numpy as np def RezMas(Mas): Mas[int(ex1[i], 16) % 10] += 1 Mas[int(ex2[i], 16) % 10] += 1 Mas[int(ex3[i], 16) % 10] += 1 Mas[int(ex4[i], 16) % 10] += 1 Mas[int(ex5[i], 16) % 10] += 1 Mas[int(ex6[i], 16) % 10] += 1 Mas[int(ex7[i], 16) % 10] += 1 def sumQR(mas1,mas2,mas3,mas4,mas5,mas6,mas7): P=Q=0 print("Мнение каких экспертов учитывать ?") p1 = int(input("p1=")) p2 = int(input("p2=")) res = np.concatenate(([mas1], [mas2], [mas3], [mas4], [mas5], [mas6], [mas7]), axis=0) k = 0 for k in range(4): for j in range(1, 5): cnt = 0 if j > k and( res[p1 - 1][k] < res[p1 - 1][j] or res[p1 - 1][k] > res[p1 - 1][j]): cnt += 1 if j > k and (res[p2 - 1][k] < res[p2 - 1][j] or res[p1 - 1][k] > res[p1 - 1][j]): cnt += 1 if cnt == 2: P += 1 if cnt != 2 and j > k: Q -= 1 rK = round((P + Q) / (0.5 * 5* 4),2) print("Коэффициент Кендалла\t rK = (P + Q) / (0.5 * n * (n-1))=", rK) ex1 = ["a", ">", "b", ">", "c", ">", "d", ">", "e"] ex2 = ["a", ">", "c", ">", "e", ">", "b", ">", "d"] ex3 = ["c", ">", "b", ">", "e", ">", "a", ">", "d"] ex4 = ["a", ">", "b", ">", "c", ">", "e", ">", "d"] ex5 = ["a", ">", "c", ">", "b", ">", "e", ">", "d"] ex6 = ["b", ">", "c", ">", "e", ">", "a", ">", "d"] ex7 = ["b", ">", "d", ">", "c", ">", "e", ">", "a"] for n in range(3): print("\nИтерация №", n+1) ex1R = [0] * 5 ex2R = [0] * 5 ex3R = [0] * 5 ex4R = [0] * 5 ex5R = [0] * 5 ex6R = [0] * 5 ex7R = [0] * 5 res1 = [0] * 5 res2 = [0] * 5 res3 = [0] * 5 res4 = [0] * 5 res5 = [0] * 5 for i in range(0, len(ex1), 2): if i == 0: ex1R[int(ex1[i], 16) % 10] += 1 ex2R[int(ex2[i], 16) % 10] += 1 ex3R[int(ex3[i], 16) % 10] += 1 ex4R[int(ex4[i], 16) % 10] += 1 ex5R[int(ex5[i], 16) % 10] += 1 ex6R[int(ex6[i], 16) % 10] += 1 ex7R[int(ex7[i], 16) % 10] += 1 RezMas(res1) if i == 2: ex1R[int(ex1[i], 16) % 10] += 2 ex2R[int(ex2[i], 16) % 10] += 2 ex3R[int(ex3[i], 16) % 10] += 2 ex4R[int(ex4[i], 16) % 10] += 2 ex5R[int(ex5[i], 16) % 10] += 2 ex6R[int(ex6[i], 16) % 10] += 2 ex7R[int(ex7[i], 16) % 10] += 2 RezMas(res2) if i == 4: ex1R[int(ex1[i], 16) % 10] += 3 ex2R[int(ex2[i], 16) % 10] += 3 ex3R[int(ex3[i], 16) % 10] += 3 ex4R[int(ex4[i], 16) % 10] += 3 ex5R[int(ex5[i], 16) % 10] += 3 ex6R[int(ex6[i], 16) % 10] += 3 ex7R[int(ex7[i], 16) % 10] += 3 RezMas(res3) if i == 6: ex1R[int(ex1[i], 16) % 10] += 4 ex2R[int(ex2[i], 16) % 10] += 4 ex3R[int(ex3[i], 16) % 10] += 4 ex4R[int(ex4[i], 16) % 10] += 4 ex5R[int(ex5[i], 16) % 10] += 4 ex6R[int(ex6[i], 16) % 10] += 4 ex7R[int(ex7[i], 16) % 10] += 4 RezMas(res4) if i == 8: ex1R[int(ex1[i], 16) % 10] += 5 ex2R[int(ex2[i], 16) % 10] += 5 ex3R[int(ex3[i], 16) % 10] += 5 ex4R[int(ex4[i], 16) % 10] += 5 ex5R[int(ex5[i], 16) % 10] += 5 ex6R[int(ex6[i], 16) % 10] += 5 ex7R[int(ex7[i], 16) % 10] += 5 RezMas(res5) REZ = [ex1R[i] + ex2R[i] + ex3R[i] + ex4R[i] + ex5R[i] + ex6R[i] + ex7R[i] for i in range(5)] REZsort = [ex1R[i] + ex2R[i] + ex3R[i] + ex4R[i] + ex5R[i] + ex6R[i] + ex7R[i] for i in range(5)] REZsort.sort() print("--------------------------------------------------") print("Экспертные ранжирования", '|', 'a', 'b', 'c', 'd', 'e') print("--------------------------------------------------") print("\t", *ex1, "|", *ex1R, sep=" ") print("\t", *ex2, "|", *ex2R, sep=" ") print("\t", *ex3, "|", *ex3R, sep=" ") print("\t", *ex4, "|", *ex4R, sep=" ") print("\t", *ex5, "|", *ex5R, sep=" ") print("\t", *ex6, "|", *ex6R, sep=" ") print("\t", *ex7, "|", *ex7R, sep=" ") print("---------------------------------------------------") print("\t\t\tСумма\t ", "|", *REZ, sep=" ") print() print("Итоговое ранжирование ---", end=" ") for i in range(len(REZsort)): for j in range(len(REZ)): if REZsort[i] == REZ[j]: print(">",hex(j + 10)[2:], end=' ') print() print() sumQR(ex1R, ex2R, ex3R, ex4R, ex5R, ex6R, ex7R) if n==0: ex1 = ["c", ">", "b", ">", "a", ">", "d", ">", "e"] ex2 = ["c", ">", "e", ">", "b", ">", "a", ">", "d"] ex3 = ["c", ">", "b", ">", "e", ">", "a", ">", "d"] ex4 = ["b", ">", "c", ">", "a", ">", "e", ">", "d"] ex5 = ["d", ">", "c", ">", "b", ">", "e", ">", "a"] ex6 = ["b", ">", "c", ">", "e", ">", "a", ">", "d"] ex7 = ["b", ">", "d", ">", "c", ">", "e", ">", "a"] if n==1: ex1 = ["d", ">", "a", ">", "b", ">", "c", ">", "e"] ex2 = ["d", ">", "e", ">", "a", ">", "b", ">", "c"] ex3 = ["d", ">", "a", ">", "e", ">", "b", ">", "c"] ex4 = ["a", ">", "d", ">", "b", ">", "e", ">", "c"] ex5 = ["d", ">", "c", ">", "a", ">", "e", ">", "b"] ex6 = ["a", ">", "d", ">", "e", ">", "b", ">", "c"] ex7 = ["b", ">", "d", ">", "c", ">", "e", ">", "a"]