Skip to content

Commit 188724f

Browse files
authored
Guard all remaining unguarded calls to create a chi^2 distribution for the case d.f. 0 (#23)
This guards all remaining calls to create a chi^2 distribution in the tests for periodicity to avoid creating with zero degrees freedom. Fixes #20.
1 parent 34fef02 commit 188724f

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

lib/maths/CPeriodicityHypothesisTests.cc

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,22 +1037,27 @@ CPeriodicityHypothesisTests::best(const TNestedHypothesesVec &hypotheses) const
10371037
TMinAccumulator vCutoff;
10381038
for (const auto &summary : summaries)
10391039
{
1040-
vCutoff.add(varianceAtPercentile(summary.s_V, summary.s_DF,
1041-
50.0 + CONFIDENCE_INTERVAL / 2.0));
1040+
if (summary.s_DF > 0.0)
1041+
{
1042+
vCutoff.add(varianceAtPercentile(summary.s_V, summary.s_DF,
1043+
50.0 + CONFIDENCE_INTERVAL / 2.0));
1044+
}
10421045
}
1043-
LOG_TRACE("variance cutoff = " << vCutoff[0]);
1044-
1045-
TMinAccumulator df;
1046-
for (const auto &summary : summaries)
1046+
if (vCutoff.count() > 0)
10471047
{
1048-
double v{varianceAtPercentile(summary.s_V, summary.s_DF,
1049-
50.0 - CONFIDENCE_INTERVAL / 2.0)};
1050-
if (v <= vCutoff[0] && df.add(-summary.s_DF))
1048+
LOG_TRACE("variance cutoff = " << vCutoff[0]);
1049+
1050+
TMinAccumulator df;
1051+
for (const auto &summary : summaries)
10511052
{
1052-
result = summary.s_H;
1053+
double v{varianceAtPercentile(summary.s_V, summary.s_DF,
1054+
50.0 - CONFIDENCE_INTERVAL / 2.0)};
1055+
if (v <= vCutoff[0] && df.add(-summary.s_DF))
1056+
{
1057+
result = summary.s_H;
1058+
}
10531059
}
10541060
}
1055-
10561061
return result;
10571062
}
10581063

@@ -1447,6 +1452,10 @@ bool CPeriodicityHypothesisTests::testPeriod(const TTimeTimePr2Vec &windows,
14471452
double B{stats.s_B};
14481453
double scale{1.0 / M};
14491454
double df0{B - stats.s_DF0};
1455+
if (df0 <= 0.0)
1456+
{
1457+
return false;
1458+
}
14501459
double v0{varianceAtPercentile(stats.s_V0, df0, 50.0 + CONFIDENCE_INTERVAL / 2.0)};
14511460
double vt{stats.s_Vt * v0};
14521461
double at{stats.s_At * std::sqrt(v0 / scale)};
@@ -1565,6 +1574,10 @@ bool CPeriodicityHypothesisTests::testPartition(const TTimeTimePr2Vec &partition
15651574
double B{stats.s_B};
15661575
double scale{1.0 / stats.s_M};
15671576
double df0{B - stats.s_DF0};
1577+
if (df0 <= 0.0)
1578+
{
1579+
return false;
1580+
}
15681581
double v0{varianceAtPercentile(stats.s_V0, df0, 50.0 + CONFIDENCE_INTERVAL / 2.0)};
15691582
double vt{stats.s_Vt * v0};
15701583
LOG_TRACE("period = " << period);

0 commit comments

Comments
 (0)