Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.23 KB | None | 0 0
  1. # %%
  2. answers = []
  3.  
  4.  
  5. def ask_image(i: int) -> bool:
  6.     img = Image.open(f'{direct}/{fileNames[i]}')
  7.     plt.imshow(img)
  8.     plt.show()
  9.     ans = ''
  10.     while ans not in ('+', '-'):
  11.         print("+/-/stop?")
  12.         ans = input()
  13.         if ans == 'stop':
  14.             raise ValueError("Stop")
  15.     answers.append(ans)
  16.     return ans == '+'
  17.  
  18.  
  19. # %%
  20. k = 1
  21.  
  22.  
  23. def run_iter(visited):
  24.     global vect
  25.  
  26.     vc = vect.copy() + 1e-4
  27.     vc[visited] = 1e9
  28.     p = softmax(1 / vc)
  29.     i = np.random.choice(amount, p=p)
  30.     while visited[i]:
  31.         i = np.random.choice(amount, p=p)
  32.     visited[i] = True
  33.     res = ask_image(i)
  34.     if res:
  35.         vect += k * (similarityMatrix[i] ** 2)
  36.     else:
  37.         vect += k / ((similarityMatrix[i] ** 2) + 1e-4)  # To avoid division by zero
  38.  
  39.  
  40. def run_cycle():
  41.     visited = np.zeros(amount, dtype=bool)
  42.     while True:
  43.         try:
  44.             run_iter(visited)
  45.         except ValueError:
  46.             break
  47.  
  48.  
  49. # %%
  50. ans_num = np.array(list(map(lambda x: x == '+', answers)), dtype=int)
  51. # %%
  52. plt.scatter(np.arange(amount), ans_num)
  53. plt.show()
  54. # %%
  55. ans_cumsum = np.cumsum(list(map(lambda x: 1 if x == 1 else -1, ans_num)))
  56. # %%
  57. plt.plot(np.arange(amount), ans_cumsum)
  58. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement