我已经为两层网络实现了 ANN,我需要用动量修改我的权重更新代码,但我需要知道如何更新它。下面是仅更新权重的代码快照。下面的代码更新了它看到的每个示例的权重,hiddenWights 是隐藏层权重,而 outputWeights 是输出层权重。
for examplen = 1: nTrainingExamples
inputVector = inputs(:,examplen);
HiddenLayerOutput = sigmoid( hiddenWeights * inputVector);
OutputLayerOutput = sigmoid( outputWeights * HiddenLayerOutput);
l2_error = OutputLayerOutput - targets(:, examplen);
l2_delta = learningRates(1, i) .* (OutputLayerOutput .* (1 - OutputLayerOutput)) .* l2_error;
l2_v = mu * l2_v - l2_delta * t;
l1_delta = learningRates(1, i) .* (HiddenLayerOutput .* (1 - HiddenLayerOutput)) .* (outputWeights' * l2_delta);
l1_v = mu * l1_v - l1_delta * t;
% weights = weights + v
outputWeights = outputWeights + (l2_v*HiddenLayerOutput');
hiddenWeights = hiddenWeights + (l1_v*inputVector');
end