diff --git a/src/NeuralNetwork/Learning/QuickPropagation.cpp b/src/NeuralNetwork/Learning/QuickPropagation.cpp index b943d48..bf9f789 100644 --- a/src/NeuralNetwork/Learning/QuickPropagation.cpp +++ b/src/NeuralNetwork/Learning/QuickPropagation.cpp @@ -5,6 +5,8 @@ void NeuralNetwork::Learning::QuickPropagation::updateWeights(const std::vector &input) { + float shrinkFactor=_maxChange/(_maxChange+1.0); + for(std::size_t layerIndex=1;layerIndex 0.0001) { + if(std::signbit(lastWeightChange[layerIndex][j]) == std::signbit(slopes[layerIndex][j])) { + newChange+= slopes[layerIndex][j]*_epsilon; - if(newChange > lastWeightChange[layerIndex][j]*_maxChange) { - newChange=lastWeightChange[layerIndex][j]; + if(fabs(slopes[layerIndex][j]) > fabs(shrinkFactor * previousSlopes[layerIndex][j])) { + newChange += _maxChange * lastWeightChange[layerIndex][j]; + }else { + newChange+=slopes[layerIndex][j]/(previousSlopes[layerIndex][j]-slopes[layerIndex][j]) * lastWeightChange[layerIndex][j]; + } + } else { + newChange+=slopes[layerIndex][j]/(previousSlopes[layerIndex][j]-slopes[layerIndex][j]) * lastWeightChange[layerIndex][j]; + } + } else { + newChange+= slopes[layerIndex][j]*_epsilon; } weightChange[layerIndex][j]=newChange;