RoboidControl-cpp/Activation.cpp
2023-11-10 15:37:35 +01:00

46 lines
1.3 KiB
C++

#include "Activation.h"
float Activation::HeavisideStep(float inputValue, float bias) {
return (inputValue + bias > 0) ? 1.0F : 0.0F;
}
float Activation::Tanh(float inputValue) {
return (exp(inputValue) - exp(-inputValue)) / (exp(inputValue) + exp(-inputValue));
}
float Activation::Sigmoid(float inputValue) {
return 1 / (1 + expf(-inputValue));
}
float Activation::Linear(float inputValue, float minValue, float range) {
if (inputValue > minValue + range)
return 0;
if (inputValue < minValue)
return 1;
float f = (inputValue - minValue) * (1 / range); // normalize to 1..0
float influence = 1 - f; // invert
return influence;
}
float Activation::Quadratic(float inputValue, float minValue, float range) {
if (inputValue > minValue + range)
return 0;
if (inputValue < minValue)
return 1;
float f = (inputValue - minValue) * (1 / range); // normalize to 1..0
float influence = 1 - (f * f); // quadratic & invert
return influence;
}
float Activation::ParticleLife(float minValue, float maxValue, float attraction, float inputValue) {
if (inputValue < minValue)
return inputValue / minValue - 1;
if (inputValue < maxValue)
return attraction * (1 - fabs(2 * inputValue - minValue - maxValue) / (maxValue - minValue));
return 0;
}