【问题标题】:Neural Network convergence speed (Levenberg-Marquardt) (MATLAB)神经网络收敛速度 (Levenberg-Marquardt) (MATLAB)
【发布时间】:2014-10-20 09:46:09
【问题描述】:

我试图用 ANN 逼近一个函数(单输入和单输出)。使用 MATLAB 工具箱,我可以看到隐藏层中有 5 个或更多神经元,我可以获得非常好的结果。所以我正在尝试手动操作。

计算: 由于网络只有一个输入和一个输出,误差相对于连接隐藏神经元 j 的权重的偏导数(e=do,其中“d”是期望输出,“o”是实际输出)对于输出神经元,将是 -hj(其中 hj 是隐藏神经元 j 的输出); 误差相对于输出偏差的偏导数将为 -1; 误差相对于将输入连接到隐藏神经元 j 的权重的偏导数将是 -woj*f'*i,其中 woj 是隐藏神经元 j 的输出权重,f' 是 tanh() 导数,' i' 是输入值; 最后,误差关于隐藏层偏差的偏导数将与上面相同(关于输入权重),除了这里我们没有输入: -woj*f'

问题是: MATLAB 算法总是收敛得更快更好。我可以实现与 MATLAB 相同的曲线,但我的算法需要更多的时期。 我试图从 MATLAB 算法中删除预处理和后处理函数。它仍然收敛得更快。 我还尝试创建和配置网络,并在训练之前提取权重/偏差值,以便我可以将它们复制到我的算法中,以查看它是否收敛更快但没有任何改变(创建/配置或训练中的权重/偏差初始化功能?)。

MATLAB 算法是否在代码中进行了某种优化? 或者这种差异可能仅在于训练集的组织和权重/偏差初始化?

如果有人想查看我的代码,这里是进行训练的主循环:

Err2 = N;
epochs = 0;
%compare MSE of error2
while ((Err2/N > 0.0003) && (u < 10000000) && (epochs < 100))
    epochs = epochs+1;
    Err = 0;
    %input->hidden weight vector
    wh = w(1:hidden_layer_len);
    %hidden->output weigth vector
    wo = w((hidden_layer_len+1):(2*hidden_layer_len));
    %hidden bias
    bi = w((2*hidden_layer_len+1):(3*hidden_layer_len));
    %output bias
    bo = w(length(w));
    %start forward propagation
    for i=1:N
        %take next input value
        x = t(i);
        %propagate to hidden layer
        neth = x*wh + bi;
        %propagate through neurons
        ij = tanh(neth)';
        %propagate to output layer
        neto = ij*wo + bo;
        %propagate to output (purelin)
        output(i) = neto;
        %calculate difference from target (error)
        error(i) = yp(i) - output(i);

        %Backpropagation:

        %tanh derivative
        fhd = 1 - tanh(neth').*tanh(neth');
        %jacobian matrix
        J(i,:) = [-x*wo'.*fhd -ij -wo'.*fhd -1];

        %SSE (sum square error)
        Err = Err + 0.5*error(i)*error(i);
    end

    %calculate next error with updated weights and compare with old error

    %start error2 from error1 + 1 to enter while loop
    Err2 = Err+1;
    %while error2 is > than old error and Mu (u) is not too large
    while ((Err2 > Err) && (u < 10000000))
        %Weight update
        w2 = w - (((J'*J + u*eye(3*hidden_layer_len+1))^-1)*J')*error';
        %New Error calculation

        %New weights to propagate
        wh = w2(1:hidden_layer_len);
        wo = w2((hidden_layer_len+1):(2*hidden_layer_len));
        %new bias to propagate
        bi = w2((2*hidden_layer_len+1):(3*hidden_layer_len));
        bo = w2(length(w));
        %calculate error2
        Err2 = 0;
        for i=1:N
            %forward propagation again
            x = t(i);
            neth = x*wh + bi;
            ij = tanh(neth)';
            neto = ij*wo + bo;
            output(i) = neto;
            error2(i) = yp(i) - output(i);

            %Error2 (SSE)
            Err2 = Err2 + 0.5*error2(i)*error2(i);
        end

        %compare MSE from error2 with a minimum
        %if greater still runing
        if (Err2/N > 0.0003)
            %compare with old error
            if (Err2 <= Err)
                %if less, update weights and decrease Mu (u)
                w = w2;
                u = u/10;
            else
                %if greater, increment Mu (u)
                u = u*10;
            end
        end
    end
end

【问题讨论】:

    标签: matlab neural-network


    【解决方案1】:

    在 Matlab 中要知道 Levenberg Marquardt 算法的确切实现并不容易。您可以尝试一次运行该算法一次迭代,看看它是否与您的算法相同。也可以试试其他的实现方式,比如http://www.mathworks.com/matlabcentral/fileexchange/16063-lmfsolve-m--levenberg-marquardt-fletcher-algorithm-for-nonlinear-least-squares-problems,看看能不能提升性能。对于简单的学习问题,收敛速度可能是学习率的问题。您可以简单地提高学习率以获得更快的收敛速度。

    【讨论】:

      猜你喜欢
      • 2012-03-03
      • 2017-05-21
      • 2016-05-13
      • 2016-07-10
      • 2019-02-20
      • 2016-05-13
      • 2018-11-04
      • 1970-01-01
      相关资源
      最近更新 更多