为什么这种反向传播实施无法正确训练权重?

Why does this backpropagation implementation fail to train weights correctly?

我已经为神经网络编写了以下反向传播例程,使用代码 here 作为示例。我面临的问题让我感到困惑,并将我的调试技能推到了极限。

我面临的问题相当简单:随着神经网络的训练,其权重被训练为零,而准确性没有提高。

我多次尝试修复,验证:

一些信息:

我不确定从这里到哪里去。我已经确认所有我知道要检查的东西都运行正常,但仍然无法正常工作,所以我在这里问。以下是我用来反向传播的代码:

def backprop(train_set, wts, bias, eta):
    learning_coef = eta / len(train_set[0])

    for next_set in train_set:
        # These record the sum of the cost gradients in the batch
        sum_del_w = [np.zeros(w.shape) for w in wts]
        sum_del_b = [np.zeros(b.shape) for b in bias]

        for test, sol in next_set:
            del_w = [np.zeros(wt.shape) for wt in wts]
            del_b = [np.zeros(bt.shape) for bt in bias]
            # These two helper functions take training set data and make them useful
            next_input = conv_to_col(test)
            outp = create_tgt_vec(sol)

            # Feedforward step
            pre_sig = []; post_sig = []
            for w, b in zip(wts, bias):
                next_input = np.dot(w, next_input) + b
                pre_sig.append(next_input)
                post_sig.append(sigmoid(next_input))
                next_input = sigmoid(next_input)

            # Backpropagation gradient
            delta = cost_deriv(post_sig[-1], outp) * sigmoid_deriv(pre_sig[-1])
            del_b[-1] = delta
            del_w[-1] = np.dot(delta, post_sig[-2].transpose())

            for i in range(2, len(wts)):
                pre_sig_vec = pre_sig[-i]
                sig_deriv = sigmoid_deriv(pre_sig_vec)
                delta = np.dot(wts[-i+1].transpose(), delta) * sig_deriv
                del_b[-i] = delta
                del_w[-i] = np.dot(delta, post_sig[-i-1].transpose())

            sum_del_w = [dw + sdw for dw, sdw in zip(del_w, sum_del_w)]
            sum_del_b = [db + sdb for db, sdb in zip(del_b, sum_del_b)]

        # Modify weights based on current batch            
        wts = [wt - learning_coef * dw for wt, dw in zip(wts, sum_del_w)]
        bias = [bt - learning_coef * db for bt, db in zip(bias, sum_del_b)]

    return wts, bias

根据 Shep 的建议,我检查了训练形状为 [2, 1, 1] 的网络始终输出 1 时发生的情况,事实上,在这种情况下网络训练正确。在这一点上,我最好的猜测是渐变对于 0s 调整得太强而在 1s 上调整太弱,导致净减少,尽管每一步都有增加 - 但我不确定。

我想你的问题在于初始权重的选择和权重算法初始化的选择。 Jeff Heaton author of Encog claims that it as usually performs worse then other initialization method. Here 是权重初始化算法性能的另一个结果。同样根据我自己的经验,建议您使用不同的符号值来初始化您的权重。即使在我拥有不同符号的所有正输出权重的情况下,也比相同符号的表现更好。