Skip to content

Commit 60d4e42

Browse files
committed
Fixed a bug related to geometric mean calculation.
1 parent 1942ec4 commit 60d4e42

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/main/java/org/panda/causalpath/analyzer/ThresholdDetector.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ public OneDataChangeDetector makeACopy()
8888
*/
8989
public double foldChangeGeometricMean(double[] vals)
9090
{
91+
if (vals.length == 1) return vals[0];
92+
9193
double mult = 1;
9294
int cnt = 0;
9395
for (double val : vals)
@@ -96,7 +98,9 @@ public double foldChangeGeometricMean(double[] vals)
9698
cnt++;
9799
mult *= val < 0 ? -1 / val : val;
98100
}
99-
return Math.pow(mult, 1D / cnt);
101+
double result = Math.pow(mult, 1D / cnt);
102+
if (result < 1) result = - 1 / result;
103+
return result;
100104
}
101105

102106
public double maxOfAbs(double[] vals)

0 commit comments

Comments
 (0)