From 368a73ccd6d5c56d125a1c3763107efb1e57e4b9 Mon Sep 17 00:00:00 2001 From: Shin Date: Sat, 21 May 2016 00:18:44 +0200 Subject: [PATCH] epochs --- .../ConstructiveAlgorithms/CascadeCorrelation.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/include/NeuralNetwork/ConstructiveAlgorithms/CascadeCorrelation.h b/include/NeuralNetwork/ConstructiveAlgorithms/CascadeCorrelation.h index 22db303..f864e95 100644 --- a/include/NeuralNetwork/ConstructiveAlgorithms/CascadeCorrelation.h +++ b/include/NeuralNetwork/ConstructiveAlgorithms/CascadeCorrelation.h @@ -31,6 +31,7 @@ namespace NeuralNetwork { network.randomizeWeights(); _epoch = 0; + _neurons = 0; float error; float lastError; if(_maxRandomOutputWeights) { @@ -38,7 +39,7 @@ namespace NeuralNetwork { } else { error = trainOutputs(network, patterns); } - while(_epoch++ < _maxHiddenUnits && error > _errorTreshold) { + while(_epoch++ < _maxHiddenUnits && _neurons++ < _maxEpochs && error > _errorTreshold) { std::vector> candidates = createCandidates(network.getNeuronSize() - outputs); std::pair, std::vector> candidate = trainCandidates(network, candidates, patterns); @@ -58,6 +59,8 @@ namespace NeuralNetwork { network.removeLastHiddenNeuron(); error=lastError; std::cout << "PRUNED\n"; + } else { + _neurons++; } } @@ -77,6 +80,10 @@ namespace NeuralNetwork { _maxHiddenUnits = neurons; } + void setMaximumEpochs(std::size_t epochs) { + _maxEpochs = epochs; + } + void setActivationFunction(const ActivationFunction::ActivationFunction &function) { _activFunction = std::shared_ptr(function.clone()); } @@ -160,6 +167,8 @@ namespace NeuralNetwork { float _pruningLimit=0.0; std::size_t _epoch = 0; + std::size_t _neurons = 0; + std::size_t _maxEpochs = 20; std::size_t _maxHiddenUnits = 20; std::size_t _maxRandomOutputWeights = 0; std::size_t _numberOfCandidates;