옛날에 풀었던 문제들 기록용으로 올려놓기
정말 기록용이라 풀이과정이나 문제 안남아있는 경우 상세히 기록 못하지만
옛날 문제들 기록 후 지금부터 뛰는 대회는 상세히 기록 할 예정
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
data_path = 'hopfield.npz'
data = np.load(data_path, allow_pickle=True)
W = data['W']
v0 = data['v0']
image_path = 'hidden-in-the-noise.png'
image = Image.open(image_path)
image_array = np.array(image)
#image_array = (image_array > 128).astype(int) * 2 - 5
flattened_image = image_array.flatten()
#flattened_image = np.append(v0[000:200],np.zeros(1000))
flattened_image = np.append(v0[0:800],np.zeros(400)) # nu
def hopfield_restore_with_image(W, initial_image, iterations=10):
v = initial_image.copy()
#v=v0
for _ in range(iterations):
v_ = np.sign(np.dot(W, v))
if np.array_equal(v,v_):
break
v = v_
return v
restored_v_with_image = hopfield_restore_with_image(W, flattened_image, iterations=1000)
restored_image_with_input = restored_v_with_image.reshape(image_array.shape)
#restored_image_with_input = flattened_image.reshape(binary_image.shape)
plt.figure(figsize=(12, 6))
plt.imshow(restored_image_with_input, cmap="gray")
plt.axis("off")
plt.show()