Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # %%
- answers = []
- def ask_image(i: int) -> bool:
- img = Image.open(f'{direct}/{fileNames[i]}')
- plt.imshow(img)
- plt.show()
- ans = ''
- while ans not in ('+', '-'):
- print("+/-/stop?")
- ans = input()
- if ans == 'stop':
- raise ValueError("Stop")
- answers.append(ans)
- return ans == '+'
- # %%
- k = 1
- def run_iter(visited):
- global vect
- vc = vect.copy() + 1e-4
- vc[visited] = 1e9
- p = softmax(1 / vc)
- i = np.random.choice(amount, p=p)
- while visited[i]:
- i = np.random.choice(amount, p=p)
- visited[i] = True
- res = ask_image(i)
- if res:
- vect += k * (similarityMatrix[i] ** 2)
- else:
- vect += k / ((similarityMatrix[i] ** 2) + 1e-4) # To avoid division by zero
- def run_cycle():
- visited = np.zeros(amount, dtype=bool)
- while True:
- try:
- run_iter(visited)
- except ValueError:
- break
- # %%
- ans_num = np.array(list(map(lambda x: x == '+', answers)), dtype=int)
- # %%
- plt.scatter(np.arange(amount), ans_num)
- plt.show()
- # %%
- ans_cumsum = np.cumsum(list(map(lambda x: 1 if x == 1 else -1, ans_num)))
- # %%
- plt.plot(np.arange(amount), ans_cumsum)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement