PROWAREtech
C/C++: Inverted Sigmoid Decay Function
A C/C++ function that returns a value nearer to an initial value in the beginning then, as the input is nears the end, it begins to decrease its output; graphed it would be nearly straight until it would steeply decrease near the end.
#include <math.h>
// Inverted Sigmoid Decay function
// This will decrease the output as each iteration completes but more so as the current iteration reaches the max number of iterations.
// gamma: Controls the sharpness of the drop-off. A higher gamma, like 100, will create a steeper decline near the end.
// delta: Shifts the decay curve closer to the end. Increasing delta (e.g., 0.9) pushes most of the drop toward the end.
// begin: This is the initial number to start with.
// end: This is the number to have at the end when maxIterations is hit.
double InvertedSigmoidDecay(double begin, double end, double currentIteration, double maxIterations, double gamma = 10, double delta = 0.9)
{
double scale = 1.0 / (1.0 + exp(-gamma * (currentIteration / maxIterations - delta)));
return end + (begin - end) * (1.0 - scale);
}
Graphed with a begin y value of 10, an end y value of 4 and a maxIterations value of 100 (default gamma and delta).
Comment