fix for values too small to be represented as Double causing NaN from StabilityDetector

This commit is contained in:
Mark Wolters 2023-12-21 15:36:06 -04:00
parent 3f6abf12f8
commit 080849ba3d
2 changed files with 6 additions and 0 deletions

View File

@ -43,6 +43,9 @@ public final class StatBucket {
} else if (Double.isNaN(popped)) {
var newMean = mean + ((value - mean) / ringbuf.count());
var dSquaredIncrement = ((value - newMean) * (value - mean));
// If this value is too small to be interpreted as a double it gets converted to
// zero, which is not what we want. So we use the smallest possible double value
if (dSquaredIncrement == 0) dSquaredIncrement = Double.MIN_VALUE;
dSquared += dSquaredIncrement;
mean = newMean;
} else {

View File

@ -41,6 +41,9 @@ public class StatFunctions {
*/
public static double sigmoidE4LowPass(double input, double highcut) {
double v = 1.0d/(1.0d + Math.pow(Math.E, (10000.0d * (input - (highcut + 0.001d)))));
// If this value is too small to be interpreted as a double it gets converted to
// zero, which is not what we want. So we use the smallest possible double value
if (v == 0) v = Double.MIN_VALUE;
return v;
}