patterns.append(array) hop = Hopfield() hop.memorize_patterns(patterns, view = view) print("Training complete. Do you want to see the weight matrices? [Y/N]") yesNo = str(raw_input()) if yesNo == 'Y' or yesNo == 'y': hop.show_patterns() print("Stating restoration...") corruptedImage = convert_image('corrupted.png') originalCorr = corruptedImage newImage = hop.update(corruptedImage) i = 0 while corruptedImage.all() != newImage.all(): print("update #{}".format(i)) corruptedImage = newImage newImage = hop.update(corruptedImage) i += 1 if i > 10000: print("Warning: forced break!") break plt.subplot(211) plt.imshow(originalCorr, cmap=plt.cm.BuPu_r, interpolation='none')
def train(train_data): model = Hopfield(0, 25) model.update(train_data) return model