gpt4 book ai didi

java - 反向传播算法-误差导数计算

转载 作者:行者123 更新时间:2023-11-30 04:52:59 25 4
gpt4 key购买 nike

在计算误差导数时,我正在使用以下方法,但不确定到底为什么。

double errorDerivative = (-output * (1-output) *(desiredOutput - output));

当我从第一个输出中删除负号时,它会失败并达到最大纪元限制。我假设从这里查看这个例子应该是这样的 http://homepages.gold.ac.uk/nikolaev/311imlti.htm不使用减号运算符。

double errorDerivative2 = (output * (1-output) *(desiredOutput - output));

我目前正在研究修改现有的 BackPropagation 实现,该实现使用随机梯度下降,并希望使其使用标准反向传播算法。目前,它看起来像这样。

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) {
System.out.println("neuron");
ArrayList<Connection> connections = n.getAllInConnections();
for (Connection con : connections) {
double output = n.getOutput();
System.out.println("final output is "+output);
double ai = con.leftNeuron.getOutput();
System.out.println("ai output is "+ai);
double desiredOutput = expectedOutput[i];

double errorDerivative = (-output * (1-output) *(desiredOutput - output));
double errorDerivative2 = (output * (1-output) *(desiredOutput - output));
System.out.println("errorDerivative is "+errorDerivative);
System.out.println("errorDerivative my one is "+(output * (1-output) *(desiredOutput - output)));
double deltaWeight = -learningRate * errorDerivative2;
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 output = 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 = output * (1 - output) * ai * sumKoutputs;
double deltaWeight = -learningRate * partialDerivative;
double newWeight = con.getWeight() + deltaWeight;
con.setDeltaWeight(deltaWeight);
con.setWeight(newWeight + momentum * con.getPrevDeltaWeight());
}
}
}

最佳答案

抱歉,我不会审查您的代码 - 没有时间,您必须带着更具体的问题回来,然后我才能帮助您。

errorDerivative2 起作用的原因可能是您正在使用权重更新规则,例如
deltaW = 学习率*errorDerivative2*输入

通常您所说的“errorDerivative2”被称为delta,定义为
-输出 * (1-输出) *(desiredOutput - 输出)
对于具有 S 形传递函数的神经元

使用权重更新规则
deltaW = -learningRate*delta*input

所以基本上它对你没有负号的 errorDerivative2 有效,因为你在另一个地方也遗漏了一个负号..

关于java - 反向传播算法-误差导数计算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9458020/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com