Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.56 KB | None | 0 0
  1. import math
  2. import random
  3. list_1 = [0.6, 0.2, 0.3, 0.2, 0.2, 0.3, 0.2, 0.2, 0.3, 0.2, 0.2, 0.3, 0.2, 0.1, 0.3, 0.3, 0.3]
  4. list_2 = [0.58, 0.18, 0.28, 0.18, 0.18, 0.28, 0.18, 0.18, 0.28, 0.18, 0.18, 0.28, 0.18, 0.4, 0.6, 0.3, 0.3]
  5.  
  6. mean_1 = sum(list_1) / len(list_1)
  7. mean_2 = sum(list_2) / len(list_2)
  8.  
  9. dist_1 = 0
  10. for i in range(0, len(list_1)) :
  11.     dist_1 += (list_1[i] - 1) * (list_1[i] - 1)
  12. dist_1 = math.sqrt(dist_1)
  13.  
  14. dist_2 = 0
  15. for i in range(0, len(list_2)) :
  16.     dist_2 += (list_2[i] - 1) * (list_2[i] - 1)
  17. dist_2 = math.sqrt(dist_2)
  18.  
  19.  
  20.  
  21. index_list = []
  22. for i in range(0, len(list_1)):
  23.     index_list.append(i)
  24.    
  25. num_of_tests = 5000
  26. all_mean_1 = 0
  27. all_mean_2 = 0
  28. count = 0
  29. equal_count = 0
  30.  
  31. part_size = 3
  32. for i in range(0, num_of_tests) :
  33.     random.shuffle(index_list)
  34.     mean_1_temp = 0
  35.     mean_2_temp = 0
  36.     for j in range(0, part_size):
  37.         mean_1_temp += list_1[index_list[j]]
  38.         mean_2_temp += list_2[index_list[j]]
  39.     mean_1_temp /= part_size
  40.     mean_2_temp /= part_size
  41.     if mean_1_temp > mean_2_temp :
  42.         count += 1
  43.     else :
  44.         if mean_1_temp == mean_2_temp :
  45.             equal_count+=1
  46.        
  47.     all_mean_1 += mean_1_temp
  48.     all_mean_2 += mean_2_temp
  49.  
  50. all_mean_1 /= num_of_tests
  51. all_mean_2 /= num_of_tests
  52.  
  53.  
  54. print(mean_1)
  55. print(mean_2)
  56. print("------------")
  57. print((count - equal_count) / (num_of_tests - equal_count))
  58. print((num_of_tests - count) / (num_of_tests - equal_count))
  59. print("------------")
  60. print(all_mean_1)
  61. print(all_mean_2)
  62. print("------------")
  63. print(dist_1)
  64. print(dist_2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement