【问题标题】:Back propagation algorithm反向传播算法
【发布时间】:2012-03-14 22:46:20
【问题描述】:

我在网上找到了一个示例,其中包含一种反向传播错误并调整权重的方法。我想知道这到底是如何工作的,以及使用了什么权重更新算法。会不会是梯度下降?

 /**
   * all output propagate back
   * 
   * @param expectedOutput
   *            first calculate the partial derivative of the error with
   *            respect to each of the weight leading into the output neurons
   *            bias is also updated here
   */
  public void applyBackpropagation(double expectedOutput[]) {

    // error check, normalize value ]0;1[
    for (int i = 0; i < expectedOutput.length; i++) {
        double d = expectedOutput[i];
        if (d < 0 || d > 1) {
            if (d < 0)
                expectedOutput[i] = 0 + epsilon;
            else
                expectedOutput[i] = 1 - epsilon;
        }
    }

    int i = 0;
    for (Neuron n : outputLayer) {
        ArrayList<Connection> connections = n.getAllInConnections();
        for (Connection con : connections) {
            double ak = n.getOutput();
            double ai = con.leftNeuron.getOutput();
            double desiredOutput = expectedOutput[i];

            double partialDerivative = -ak * (1 - ak) * ai
                    * (desiredOutput - ak);
            double deltaWeight = -learningRate * partialDerivative;
            double newWeight = con.getWeight() + deltaWeight;
            con.setDeltaWeight(deltaWeight);
            con.setWeight(newWeight + momentum * con.getPrevDeltaWeight());
        }
        i++;
    }

    // update weights for the hidden layer
    for (Neuron n : hiddenLayer) {
        ArrayList<Connection> connections = n.getAllInConnections();
        for (Connection con : connections) {
            double aj = n.getOutput();
            double ai = con.leftNeuron.getOutput();
            double sumKoutputs = 0;
            int j = 0;
            for (Neuron out_neu : outputLayer) {
                double wjk = out_neu.getConnection(n.id).getWeight();
                double desiredOutput = (double) expectedOutput[j];
                double ak = out_neu.getOutput();
                j++;
                sumKoutputs = sumKoutputs
                        + (-(desiredOutput - ak) * ak * (1 - ak) * wjk);
            }

            double partialDerivative = aj * (1 - aj) * ai * sumKoutputs;
            double deltaWeight = -learningRate * partialDerivative;
            double newWeight = con.getWeight() + deltaWeight;
            con.setDeltaWeight(deltaWeight);
            con.setWeight(newWeight + momentum * con.getPrevDeltaWeight());
        }
    }
}

【问题讨论】:

  • 据我所知,这表示具有一个隐藏层的 MLP。如果无法遵循这段代码,我猜反向传播会导致梯度下降。你的问题到底是什么?如果你可以使用这个代码或者梯度下降是什么?

标签: java algorithm neural-network backpropagation gradient-descent


【解决方案1】:

这篇看起来很丑的文章似乎描述了完全相同的算法版本:http://www.speech.sri.com/people/anand/771/html/node37.html。我的大学论文中有相同的公式,但遗憾的是:a)它们无法在线获得; b) 它们的语言是你不会理解的。

对于梯度下降,算法类似于梯度下降,但不能保证达到最优位置。在每一步中,网络边都会改变它们的值,从而增加训练样本值的概率。

【讨论】:

    【解决方案2】:

    在我看来,这个解决方案使用stochastic gradient descent。它与常规梯度下降的主要区别在于,梯度是为每个示例近似的,而不是为所有示例计算梯度,然后选择最佳方向。这是实现反向传播的常用方法,甚至对梯度下降有一些优势(可以避免一些局部最小值)。我相信这篇文章也解释了这个想法是什么,还有很多其他文章解释了反向传播背后的主要思想。

    【讨论】:

    • 如果这是 SGD,那么训练样本的循环在哪里?输出单元上有一个循环递增i,好像输出单元的数量等于训练样本的数量,这似乎完全荒谬。
    • 我认为应该有一个循环调用此函数,实际上该函数仅将权重调整为单个样本。这是因为函数的唯一输入是所有输出感知器的期望值(每个神经元只有一个值)。
    • 啊,对了!我期待expectedOutput 的长度为n_samples
    猜你喜欢
    • 2014-01-10
    • 2013-11-28
    • 1970-01-01
    • 2016-10-16
    • 2017-05-12
    • 2014-08-04
    • 1970-01-01
    • 2017-06-09
    相关资源
    最近更新 更多