2016-11-21 91 views
1

enter image description here在Python

錯誤的向後傳播我試圖理解的錯誤的傳播有多麼的落後工作的,所以我想用上面顯示的非常簡單的神經網絡來做到這一點。

我已經做了以下至今:

import numpy as np 

def forward_propagation(X, theta_1, theta_2): 
    z2 = np.dot(X, theta_1) 
    a2 = sigmoid(z2) 
    z3 = np.dot(a2, theta_2) 
    y = sigmoid(z3) 
    return y 

def sigmoid(z): 
    return 1/(1 + np.exp(-z)) 

if __name__ == '__main__': 
    input_layer = 1 
    hidden_layer = 1 
    output_layer = 1 

    # theta_1 = np.random.randn(input_layer, hidden_layer) 
    # theta_2 = np.random.randn(hidden_layer, output_layer) 

    theta_1 = np.array(([0.2])) 
    theta_2 = np.array(([0.1])) 

    X = np.array(([-5]), dtype=float) 
    predicted_y = forward_propagation(X, theta_1, theta_2) 
    print predicted_y 
    Y = np.array(([1]), dtype=float) 

與輸出:

[ 0.50672313] 

所以我現在Y的激活,但我完全不明白怎麼可以做向後傳播,並更新參數theta_1theta_2。我一直在試圖與this video跟着,但我完全不明白。我發現其他視頻似乎也做向後誤差傳播方式不同,所以它只是讓我更糊塗了。

回答

0

我會試圖瞭解詳細信息梯度下降,並可能計算它的一個簡單的任務,如Logistic迴歸或任何其他基於梯度的最小二乘任務,通過筆和紙開始。藉助神經網絡,理解差異化的鏈條規則也非常重要。

如果你得到這個正確的,你可以開始將其應用於神經網絡。它會清理很多東西。