Trying to implement the Storkey rule...
I can use the below algorithm to train an initial pattern -- because it goes into the if statement and simply uses the hebbian learning/outer-product method. But if I then try to train a new pattern on top of those old weights, something odd happens: the network, when presented with the new pattern, still converges on the old one...
I think the error is with how I am computing the variable post_synaptic
...?
def storkey_rule(pattern, old_weights=None):
"""
pattern: 2-dimensional array
old_weights: square array of length pattern.shape[0]*pattern.shape[1]
"""
mem = pattern.flatten()
n = len(mem)
if type(old_weights) == type(None):
new_weights = np.outer(mem,mem) - np.identity(n)
return new_weights
hebbian_term = np.outer(mem,mem) - np.identity(n)
net_inputs = old_weights.dot(mem) #equivalent to (but faster than?) np.matmul(old_weights, mem)
# I think pre_synpatic can stay put...
pre_synaptic = np.outer(mem,net_inputs)
# but post-synaptic has to be changed somehow....?
post_synaptic = pre_synaptic.T #equivalent to np.outer(net_inputs,mem)
new_weights = old_weights + (1./n)*(hebbian_term - pre_synaptic - post_synaptic)
return new_weights
Here's a link to the jupyter notebook where I'm developing this. You can see that when I try to train and then expose the network on/to the Neil deGrasse Tyson image, it still settles on the 'Deal with it' image it was initially trained on.