Exp 6ml
Exp 6ml
Exp 6ml
import numpy as np
import math
import time
np.set_printoptions(threshold=np.inf)
X = np.array([[1,-2,0,-1],[0,1.5,-0.5,-1],[-1,1,0.5,-1]])
D=np.array([-1,-1,1])
c=0.1;
W=np.array([[1,-1,0,0.5]])
e_max=0.1
#e_max=0.0001
#print(W)
while(1):
e=0
for i in range(3):
#y=X[0]
y=[X[i]]
#print(y)
net =sum(sum(W*y))
#print("\n Net is :",net)
O=(2/(1+math.exp(-net)))-1
#print("\n O is :",O)
e=e+(1/2)*(D[i]-O)**2
f_net=(1/2)*(1-O**2)
W_new=W+(np.asarray(c*(D[i]-O))*(y)*f_net)
#print("\n f'(net) :",f_net)
W=W_new
print("\n New weight is :",W)
time.sleep(1)
if e<=e_max:
break
// Output
New weight is : [[ 0.97408569 -0.94817138 0. 0.52591431]]