Search in sources :

Example 1 with MutualInformation

use of org.opensearch.search.aggregations.bucket.terms.heuristic.MutualInformation in project OpenSearch by opensearch-project.

the class SignificantTermsSignificanceScoreIT method testBackgroundVsSeparateSet.

public void testBackgroundVsSeparateSet() throws Exception {
    String type = randomBoolean() ? "text" : "long";
    String settings = "{\"index.number_of_shards\": 1, \"index.number_of_replicas\": 0}";
    SharedSignificantTermsTestMethods.index01Docs(type, settings, this);
    testBackgroundVsSeparateSet(new MutualInformation(true, true), new MutualInformation(true, false), type);
    testBackgroundVsSeparateSet(new ChiSquare(true, true), new ChiSquare(true, false), type);
    testBackgroundVsSeparateSet(new GND(true), new GND(false), type);
}
Also used : ChiSquare(org.opensearch.search.aggregations.bucket.terms.heuristic.ChiSquare) MutualInformation(org.opensearch.search.aggregations.bucket.terms.heuristic.MutualInformation) GND(org.opensearch.search.aggregations.bucket.terms.heuristic.GND)

Example 2 with MutualInformation

use of org.opensearch.search.aggregations.bucket.terms.heuristic.MutualInformation in project OpenSearch by opensearch-project.

the class SignificanceHeuristicTests method getRandomSignificanceheuristic.

public static SignificanceHeuristic getRandomSignificanceheuristic() {
    List<SignificanceHeuristic> heuristics = new ArrayList<>();
    heuristics.add(new JLHScore());
    heuristics.add(new MutualInformation(randomBoolean(), randomBoolean()));
    heuristics.add(new GND(randomBoolean()));
    heuristics.add(new ChiSquare(randomBoolean(), randomBoolean()));
    return heuristics.get(randomInt(3));
}
Also used : JLHScore(org.opensearch.search.aggregations.bucket.terms.heuristic.JLHScore) ChiSquare(org.opensearch.search.aggregations.bucket.terms.heuristic.ChiSquare) ArrayList(java.util.ArrayList) SignificanceHeuristic(org.opensearch.search.aggregations.bucket.terms.heuristic.SignificanceHeuristic) MutualInformation(org.opensearch.search.aggregations.bucket.terms.heuristic.MutualInformation) GND(org.opensearch.search.aggregations.bucket.terms.heuristic.GND)

Example 3 with MutualInformation

use of org.opensearch.search.aggregations.bucket.terms.heuristic.MutualInformation in project OpenSearch by opensearch-project.

the class SignificanceHeuristicTests method testAssertions.

public void testAssertions() throws Exception {
    testBackgroundAssertions(new MutualInformation(true, true), new MutualInformation(true, false));
    testBackgroundAssertions(new ChiSquare(true, true), new ChiSquare(true, false));
    testBackgroundAssertions(new GND(true), new GND(false));
    testAssertions(new PercentageScore());
    testAssertions(new JLHScore());
}
Also used : JLHScore(org.opensearch.search.aggregations.bucket.terms.heuristic.JLHScore) ChiSquare(org.opensearch.search.aggregations.bucket.terms.heuristic.ChiSquare) MutualInformation(org.opensearch.search.aggregations.bucket.terms.heuristic.MutualInformation) GND(org.opensearch.search.aggregations.bucket.terms.heuristic.GND) PercentageScore(org.opensearch.search.aggregations.bucket.terms.heuristic.PercentageScore)

Example 4 with MutualInformation

use of org.opensearch.search.aggregations.bucket.terms.heuristic.MutualInformation in project OpenSearch by opensearch-project.

the class SignificanceHeuristicTests method testScoreMutual.

public void testScoreMutual() throws Exception {
    SignificanceHeuristic heuristic = new MutualInformation(true, true);
    assertThat(heuristic.getScore(1, 1, 1, 3), greaterThan(0.0));
    assertThat(heuristic.getScore(1, 1, 2, 3), lessThan(heuristic.getScore(1, 1, 1, 3)));
    assertThat(heuristic.getScore(2, 2, 2, 4), equalTo(1.0));
    assertThat(heuristic.getScore(0, 2, 2, 4), equalTo(1.0));
    assertThat(heuristic.getScore(2, 2, 4, 4), equalTo(0.0));
    assertThat(heuristic.getScore(1, 2, 2, 4), equalTo(0.0));
    assertThat(heuristic.getScore(3, 6, 9, 18), equalTo(0.0));
    double score = 0.0;
    try {
        long a = randomLong();
        long b = randomLong();
        long c = randomLong();
        long d = randomLong();
        score = heuristic.getScore(a, b, c, d);
    } catch (IllegalArgumentException e) {
    }
    assertThat(score, lessThanOrEqualTo(1.0));
    assertThat(score, greaterThanOrEqualTo(0.0));
    heuristic = new MutualInformation(false, true);
    assertThat(heuristic.getScore(0, 1, 2, 3), equalTo(Double.NEGATIVE_INFINITY));
    heuristic = new MutualInformation(true, false);
    score = heuristic.getScore(2, 3, 1, 4);
    assertThat(score, greaterThanOrEqualTo(0.0));
    assertThat(score, lessThanOrEqualTo(1.0));
    score = heuristic.getScore(1, 4, 2, 3);
    assertThat(score, greaterThanOrEqualTo(0.0));
    assertThat(score, lessThanOrEqualTo(1.0));
    score = heuristic.getScore(1, 3, 4, 4);
    assertThat(score, greaterThanOrEqualTo(0.0));
    assertThat(score, lessThanOrEqualTo(1.0));
}
Also used : SignificanceHeuristic(org.opensearch.search.aggregations.bucket.terms.heuristic.SignificanceHeuristic) MutualInformation(org.opensearch.search.aggregations.bucket.terms.heuristic.MutualInformation)

Example 5 with MutualInformation

use of org.opensearch.search.aggregations.bucket.terms.heuristic.MutualInformation in project OpenSearch by opensearch-project.

the class SignificanceHeuristicTests method testBuilderAndParser.

// test that
// 1. The output of the builders can actually be parsed
// 2. The parser does not swallow parameters after a significance heuristic was defined
public void testBuilderAndParser() throws Exception {
    // test jlh with string
    assertTrue(parseFromString("\"jlh\":{}") instanceof JLHScore);
    // test gnd with string
    assertTrue(parseFromString("\"gnd\":{}") instanceof GND);
    // test mutual information with string
    boolean includeNegatives = randomBoolean();
    boolean backgroundIsSuperset = randomBoolean();
    String mutual = "\"mutual_information\":{\"include_negatives\": " + includeNegatives + ", \"background_is_superset\":" + backgroundIsSuperset + "}";
    assertEquals(new MutualInformation(includeNegatives, backgroundIsSuperset), parseFromString(mutual));
    String chiSquare = "\"chi_square\":{\"include_negatives\": " + includeNegatives + ", \"background_is_superset\":" + backgroundIsSuperset + "}";
    assertEquals(new ChiSquare(includeNegatives, backgroundIsSuperset), parseFromString(chiSquare));
    // test with builders
    assertThat(parseFromBuilder(new JLHScore()), instanceOf(JLHScore.class));
    assertThat(parseFromBuilder(new GND(backgroundIsSuperset)), instanceOf(GND.class));
    assertEquals(new MutualInformation(includeNegatives, backgroundIsSuperset), parseFromBuilder(new MutualInformation(includeNegatives, backgroundIsSuperset)));
    assertEquals(new ChiSquare(includeNegatives, backgroundIsSuperset), parseFromBuilder(new ChiSquare(includeNegatives, backgroundIsSuperset)));
    // test exceptions
    String expectedError = "unknown field [unknown_field]";
    checkParseException("\"mutual_information\":{\"include_negatives\": false, \"unknown_field\": false}", expectedError);
    checkParseException("\"chi_square\":{\"unknown_field\": true}", expectedError);
    checkParseException("\"jlh\":{\"unknown_field\": true}", expectedError);
    checkParseException("\"gnd\":{\"unknown_field\": true}", expectedError);
}
Also used : JLHScore(org.opensearch.search.aggregations.bucket.terms.heuristic.JLHScore) ChiSquare(org.opensearch.search.aggregations.bucket.terms.heuristic.ChiSquare) MutualInformation(org.opensearch.search.aggregations.bucket.terms.heuristic.MutualInformation) Matchers.containsString(org.hamcrest.Matchers.containsString) GND(org.opensearch.search.aggregations.bucket.terms.heuristic.GND)

Aggregations

MutualInformation (org.opensearch.search.aggregations.bucket.terms.heuristic.MutualInformation)7 ChiSquare (org.opensearch.search.aggregations.bucket.terms.heuristic.ChiSquare)6 GND (org.opensearch.search.aggregations.bucket.terms.heuristic.GND)5 JLHScore (org.opensearch.search.aggregations.bucket.terms.heuristic.JLHScore)4 PercentageScore (org.opensearch.search.aggregations.bucket.terms.heuristic.PercentageScore)2 SignificanceHeuristic (org.opensearch.search.aggregations.bucket.terms.heuristic.SignificanceHeuristic)2 ArrayList (java.util.ArrayList)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1