2016-11-21 94 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回归或任何其他基于梯度的最小二乘任务,通过笔和纸开始。借助神经网络,理解差异化的链条规则也非常重要。

如果你得到这个正确的,你可以开始将其应用于神经网络。它会清理很多东西。