import numpy as np import random import math Q1 = np.random.random() Q2 = np.random.random() x=np.array([[0,0], [0,1], [1,0], [1,1]]) t=np.array([[0], [0], [0], [1]]) Q0=0 a = 0.01 eps = 1e-4 e0 = 0.001 e1 = 0.001 e2 = 0.001 while e0>=eps or e1>=eps or e2>=eps: j=random.randint(0,3) i=j r=math.e**(-1) k=Q0+Q1*x[i,0]+Q2*x[i,1] sig=1/(1+r**k) e0 = (sig-t[i])*sig*(1-sig) e1 = (sig-t[i])*sig*(1-sig)*x[i,0] e2 = (sig-t[i])*sig*(1-sig)*x[i,1] else: Q0 = Q0-a*e0 Q1 = Q1-a*e1 Q2 = Q2-a*e2 print(Q0,Q1,Q2)
[0.0005269] [0.62731144] [0.37671326]