diff options
author | Justin Wernick <justin@worthe-it.co.za> | 2022-04-19 21:24:15 +0200 |
---|---|---|
committer | Justin Wernick <justin@worthe-it.co.za> | 2022-04-19 21:24:15 +0200 |
commit | 8eebf1079fbed2848ee47cf990f5def5926a0c1f (patch) | |
tree | b51a6cc24fb900c717bf479d357a9ae8a98e07ef /2015-spacebot/src/brain/neuron.cpp | |
parent | 550caeee11086bd56db69176b3149ddfa160ee30 (diff) |
Refile for merging repos
Diffstat (limited to '2015-spacebot/src/brain/neuron.cpp')
-rw-r--r-- | 2015-spacebot/src/brain/neuron.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/2015-spacebot/src/brain/neuron.cpp b/2015-spacebot/src/brain/neuron.cpp new file mode 100644 index 0000000..c7dba2c --- /dev/null +++ b/2015-spacebot/src/brain/neuron.cpp @@ -0,0 +1,40 @@ +#include "brain/neuron.h" +#include <cmath> + +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; +} |