Problem in convergence of hebbian learning approach for Fuzzy Cognitive Map
I was trying to learn Fuzzy Cognitive Map by Active Hebbian Learning approach from here. What I have understand is that the model learns iteratively, at each step a new concept values enters and tune the weighs until the MSE score in output neurone is very small. 458
I thaught that it is similar to stochastic gradient descent. But I don't see any convergence in output MSE value when a new input comes.
import numpy as np
import matplotlib.pyplot as plt
mean1 = [0, 0]
cov1 = [[1, 0], [0, 1]]
x1, x2 = np.random.multivariate_normal(mean1, cov1, 10000).T
x1 = x1.reshape([len(x1),1])
x2 = x2.reshape([len(x2),1])
def multivariate_normal(x, d, mean, covariance):
"""pdf of the multivariate normal distribution."""
x_m = x - mean
return (1. / (np.sqrt((2 * np.pi)**d * np.linalg.det(covariance))) *
np.exp(-(np.linalg.solve(covariance, x_m).T.dot(x_m)) / 2))
def sigmoid(x):
return 1/(1+np.exp(-x))
def FCM(W,X1,X2,y,lr,gamma):
y1 = 0
y2 = 0
loss = []
Loss = []
for i in range(0,2000):
A1 = np.dot(W[0],np.transpose(X1[i]))
A1 = A1.astype('float')
A2 = np.dot(W[1],np.transpose(X2[i]))
A2 = A2.astype('float')
y1 = sigmoid(A1 + y[i][0])
y2 = sigmoid(A2 + y[i][1])
temp = ((y1 - y[i][0])**2 + (y2 - y[i][1])**2)/2
print(i)
Loss.append(temp)
count = 0
while (count < 1):
count += 1
#print(temp)
A1 = np.dot(W[0],np.transpose(X1[i]))
A1 = A1.astype('float')
A2 = np.dot(W[1],np.transpose(X2[i]))
A2 = A2.astype('float')
y1 = sigmoid(A1 + y[i][0])
y2 = sigmoid(A2 + y[i][1])
temp1 = (1 - gamma)*W[0] + lr*X1[i]*y[i][0]
temp2 = (1 - gamma)*W[1] + lr*X2[i]*y[i][1]
#print(temp1,temp2)
W[0] = temp1/(np.sqrt(np.dot(temp1,np.transpose(temp1))+np.dot(temp2,np.transpose(temp2))))
W[1] = temp2/(np.sqrt(np.dot(temp2,np.transpose(temp2))+np.dot(temp1,np.transpose(temp1))))
A1 = np.dot(W[0],np.transpose(X1[i]))
A1 = A1.astype('float')
A2 = np.dot(W[1],np.transpose(X2[i]))
A2 = A2.astype('float')
y1 = sigmoid(A1 + y[i][0])
y2 = sigmoid(A2 + y[i][1])
temp = ((y1 - y[i][0])**2 + (y2 - y[i][1])**2)/2
loss.append(temp)
if count > 1:
if loss[len(loss) - 1] > loss[len(loss) - 2]:
break
# Loss.append(temp)
return [W,Loss]
X = np.concatenate((x1,x2),axis = 1)
"""
from sklearn. 509