int EntropyMethod::computeThreshold(const Histogram &histogram) { int threshold = 0; double max_evaluation = computeEvaluation(histogram, 0); for (int i = 1; i <= MAX_PIXEL_VALUE; ++i) { double evaluation = computeEvaluation(histogram, i); if (evaluation > max_evaluation) { threshold = i; max_evaluation = evaluation; } } return threshold; }
/** * Return the typed value of Term evaluation with respect * to Bounder Symbol values */ inline const T& evaluate(const Bounder& bounder) { if (!_isValueComputed) { _value = computeEvaluation(bounder); _isValueComputed = true; } return _value; }
void Network::computeTraining(double alpha, const std::vector<double> & data, const std::vector<double> & knowledge) { assert(_outputNeurons.size() == knowledge.size()); // evaluate network computeEvaluation(data); // compute training errors of all neurons std::set<int> set1; std::set<int> set2; std::set<int> * ptrCurrentSet = &set1; std::set<int> * ptrNextSet = &set2; std::vector<double> errors(_neuronValues.size(), 0.0); // compute local training for output neurons for (unsigned x=0; x<_outputNeurons.size(); x++) { int j=_outputNeurons[x]; computeLocalOutputTraining(j, knowledge[x], errors); ptrCurrentSet->insert(j); } // update neurons using multiple passes // from output neurons to input neurons while (not ptrCurrentSet->empty()) { // for each neuron of the set to update for (int j : *ptrCurrentSet) { // update error for j computeLocalHiddenTraining(j, errors); // get input neurons for the next updating pass for (int i=0; i<_synapseConnections.rows(); i++) { if (_synapseConnections(i,j) != 0) { ptrNextSet->insert(i); } } } // go to next updating pass std::swap(ptrCurrentSet, ptrNextSet); ptrNextSet->clear(); } // update synapse weights for (int i=0; i<_synapseWeights.rows(); i++) { for (int j=0; j<_synapseWeights.cols(); j++) { if (_synapseConnections(i,j) != 0) { _synapseWeights(i,j) += alpha * errors[j] * _neuronValues(i); } } } }