728x90
반응형
x, w, b, yT, lr = 2, 3, 1, 10, 0.01

for epoch in range(2000):
    y = (x * w) + (1 + b)
    E = (y - yT) ** 2/2
    yE = y - yT
    wE = yE * x
    bE = yE * 1
    w = w - lr * wE
    b = b - lr * bE
    
    if E < 0.0000001:
        break
    
    print("epoch = %d" % epoch)
    print("y = %6.3f" %y)
    print("wE = %6.3f, bE = %6.3f" %(wE, bE))
    print("w : %f, b : %f" %(w,b))
x1, x2 = 2, 3
w1, w2 = 3, 4
b, yT, lr = 1, 27, 0.01

for epoch in range(2000):
    y = (x1 * w1) + (x2 * w2) + (1 + b)
    E = (y - yT) ** 2 / 2
    yE = y - yT;
    x1E, x2E = yE - w1, yE - w2
    w1E, w2E = yE * x1, yE * x2
    bE = yE * 1
    
    w1 -= lr * w1E
    w2 -= lr * w2E
    b -= lr * bE
    
    print("epoch = %d" %epoch)
    print("예측값(y) = %6.3f" %y)
    print("가중치(w1) = %6.3f (w2) = %6.3f" %(w1, w2))
    print("가중치 역전파(w1E) = %6.3f, (w2E) = %6.3f, 편향 역전파(bE) = %6.3f" %(w1E, w2E, bE))
    
    if (E < 0.0000001): 
        break
728x90
반응형

+ Recent posts