Skip to content

Commit 5807eb8

Browse files
committed
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 d26ab95 commit 5807eb8

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
@@ -1046,22 +1046,27 @@ CPeriodicityHypothesisTests::best(const TNestedHypothesesVec &hypotheses) const
10461046
TMinAccumulator vCutoff;
10471047
for (const auto &summary : summaries)
10481048
{
1049-
vCutoff.add(varianceAtPercentile(summary.s_V, summary.s_DF,
1050-
50.0 + CONFIDENCE_INTERVAL / 2.0));
1049+
if (summary.s_DF > 0.0)
1050+
{
1051+
vCutoff.add(varianceAtPercentile(summary.s_V, summary.s_DF,
1052+
50.0 + CONFIDENCE_INTERVAL / 2.0));
1053+
}
10511054
}
1052-
LOG_TRACE("variance cutoff = " << vCutoff[0]);
1053-
1054-
TMinAccumulator df;
1055-
for (const auto &summary : summaries)
1055+
if (vCutoff.count() > 0)
10561056
{
1057-
double v{varianceAtPercentile(summary.s_V, summary.s_DF,
1058-
50.0 - CONFIDENCE_INTERVAL / 2.0)};
1059-
if (v <= vCutoff[0] && df.add(-summary.s_DF))
1057+
LOG_TRACE("variance cutoff = " << vCutoff[0]);
1058+
1059+
TMinAccumulator df;
1060+
for (const auto &summary : summaries)
10601061
{
1061-
result = summary.s_H;
1062+
double v{varianceAtPercentile(summary.s_V, summary.s_DF,
1063+
50.0 - CONFIDENCE_INTERVAL / 2.0)};
1064+
if (v <= vCutoff[0] && df.add(-summary.s_DF))
1065+
{
1066+
result = summary.s_H;
1067+
}
10621068
}
10631069
}
1064-
10651070
return result;
10661071
}
10671072

@@ -1456,6 +1461,10 @@ bool CPeriodicityHypothesisTests::testPeriod(const TTimeTimePr2Vec &windows,
14561461
double B{stats.s_B};
14571462
double scale{1.0 / M};
14581463
double df0{B - stats.s_DF0};
1464+
if (df0 <= 0.0)
1465+
{
1466+
return false;
1467+
}
14591468
double v0{varianceAtPercentile(stats.s_V0, df0, 50.0 + CONFIDENCE_INTERVAL / 2.0)};
14601469
double vt{stats.s_Vt * v0};
14611470
double at{stats.s_At * std::sqrt(v0 / scale)};
@@ -1574,6 +1583,10 @@ bool CPeriodicityHypothesisTests::testPartition(const TTimeTimePr2Vec &partition
15741583
double B{stats.s_B};
15751584
double scale{1.0 / stats.s_M};
15761585
double df0{B - stats.s_DF0};
1586+
if (df0 <= 0.0)
1587+
{
1588+
return false;
1589+
}
15771590
double v0{varianceAtPercentile(stats.s_V0, df0, 50.0 + CONFIDENCE_INTERVAL / 2.0)};
15781591
double vt{stats.s_Vt * v0};
15791592
LOG_TRACE("period = " << period);

0 commit comments

Comments
 (0)