#include "brain/neuron.h" #include double Neuron::sigmoid(double input) const { const double slope = 4.924273; return (1/(1+(std::exp(-(slope*input))))); } bool Neuron::calculateActivation() { double newActivation = 0; for (auto const& link : _inputLinks) { newActivation += link.weightedActivation(); } newActivation = sigmoid(newActivation); const double errorMargin = 0.000001; bool activationChanged = std::abs(newActivation - _activation) > errorMargin; _activation = newActivation; return activationChanged; } void Neuron::addInput(NeuralLink&& link) { _inputLinks.push_back(std::move(link)); } bool Neuron::hasInputWithWeight(std::string srcIdentifier, double weight) const { for (auto const& link : _inputLinks) { if (link.inputIdentifier() == srcIdentifier && link.weight() == weight) { return true; } } return false; }