Skip to content

[ML] make p_value scoring tests more robust #75629

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,32 +66,39 @@ public void testPValueScore_WhenAllDocsContainTerm() {
assertThat(pValueScore.getScore(subsetCount, subsetCount, supersetCount, supersetCount), equalTo(0.0));
}

@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/75601")
public void testHighPValueScore() {
boolean backgroundIsSuperset = randomBoolean();
// supersetFreqCount needs to at less than 20% ratio
long supersetCount = randomLongBetween(0L, Long.MAX_VALUE/2);
long subsetCount = randomLongBetween(0L, supersetCount);
long supersetFreqCount = randomLongBetween(0L, (long)(supersetCount/5.0));
// subsetFreqCount needs to be at least 25% ratio
long subsetCount = randomLongBetween((long)(supersetCount/4.0), supersetCount);
long subsetFreqCount = randomLongBetween((long)(subsetCount/4.0), subsetCount);
if (backgroundIsSuperset) {
supersetCount += subsetCount;
supersetFreqCount += subsetFreqCount;
}

PValueScore pValueScore = new PValueScore(backgroundIsSuperset);
assertThat(pValueScore.getScore(subsetCount, subsetCount, subsetCount, supersetCount), greaterThanOrEqualTo(700.0));
assertThat(pValueScore.getScore(subsetFreqCount, subsetCount, supersetFreqCount, supersetCount), greaterThanOrEqualTo(700.0));
}

@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/75601")
public void testLowPValueScore() {
boolean backgroundIsSuperset = randomBoolean();
// supersetFreqCount needs to at least be 20% ratio
long supersetCount = randomLongBetween(0L, Long.MAX_VALUE/2);
long subsetCount = randomLongBetween(0L, supersetCount);
long subsetFreqCount = randomLongBetween(0L, subsetCount/5);
long supersetFreqCount = randomLongBetween((long)(supersetCount/5.0), supersetCount);
// subsetFreqCount needs to be less than 16% ratio
long subsetCount = randomLongBetween((long)(supersetCount/5.0), supersetCount);
long subsetFreqCount = randomLongBetween(0L, (long)(subsetCount/6.0));
if (backgroundIsSuperset) {
supersetCount += subsetCount;
supersetFreqCount += subsetFreqCount;
}

PValueScore pValueScore = new PValueScore(backgroundIsSuperset);
assertThat(
pValueScore.getScore(subsetFreqCount, subsetCount, subsetCount, supersetCount),
pValueScore.getScore(subsetFreqCount, subsetCount, supersetFreqCount, supersetCount),
allOf(lessThanOrEqualTo(5.0), greaterThanOrEqualTo(0.0))
);
}
Expand Down