-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: jzonthemtn <[email protected]>
- Loading branch information
1 parent
cec6de1
commit 8d80e2e
Showing
8 changed files
with
237 additions
and
177 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
...-quality-evaluation-plugin/src/main/java/org/opensearch/eval/metrics/DcgSearchMetric.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
package org.opensearch.eval.metrics; | ||
|
||
import java.util.List; | ||
|
||
public class DcgSearchMetric extends SearchMetric { | ||
|
||
protected final List<Double> relevanceScores; | ||
|
||
public DcgSearchMetric(final int k, final List<Double> relevanceScores) { | ||
super(k); | ||
this.relevanceScores = relevanceScores; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "dcg_at_" + k; | ||
} | ||
|
||
@Override | ||
public double calculate() { | ||
|
||
double dcg = 0.0; | ||
for(int i = 0; i < relevanceScores.size(); i++) { | ||
double relevance = relevanceScores.get(i); | ||
dcg += relevance / Math.log(i + 2); // Add 2 to avoid log(1) = 0 | ||
} | ||
return dcg; | ||
|
||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
...quality-evaluation-plugin/src/main/java/org/opensearch/eval/metrics/NdcgSearchMetric.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
package org.opensearch.eval.metrics; | ||
|
||
import java.util.List; | ||
|
||
public class NdcgSearchMetric extends DcgSearchMetric { | ||
|
||
private final List<Double> idealRelevanceScores; | ||
|
||
public NdcgSearchMetric(final int k, final List<Double> relevanceScores, final List<Double> idealRelevanceScores) { | ||
super(k, relevanceScores); | ||
this.idealRelevanceScores = idealRelevanceScores; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "ndcg_at_" + k; | ||
} | ||
|
||
@Override | ||
public double calculate() { | ||
|
||
double dcg = super.calculate(); | ||
|
||
double idcg = 0.0; | ||
for(int i = 0; i < idealRelevanceScores.size(); i++) { | ||
double relevance = idealRelevanceScores.get(i); | ||
idcg += relevance / Math.log(i + 2); // Add 2 to avoid log(1) = 0 | ||
} | ||
|
||
if(idcg == 0) { | ||
return 0; | ||
} | ||
|
||
return dcg / idcg; | ||
|
||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
...ty-evaluation-plugin/src/main/java/org/opensearch/eval/metrics/PrecisionSearchMetric.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
package org.opensearch.eval.metrics; | ||
|
||
import java.util.List; | ||
|
||
public class PrecisionSearchMetric extends SearchMetric { | ||
|
||
private final List<Double> relevanceScores; | ||
|
||
public PrecisionSearchMetric(final int k, final List<Double> relevanceScores) { | ||
super(k); | ||
this.relevanceScores = relevanceScores; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "precision_at_" + k; | ||
} | ||
|
||
@Override | ||
public double calculate() { | ||
|
||
// TODO: Implement this. | ||
return 0.0; | ||
|
||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
...rch-quality-evaluation-plugin/src/main/java/org/opensearch/eval/metrics/SearchMetric.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
package org.opensearch.eval.metrics; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
public abstract class SearchMetric { | ||
|
||
private static final Logger LOGGER = LogManager.getLogger(SearchMetric.class); | ||
|
||
protected int k; | ||
|
||
public abstract String getName(); | ||
|
||
public abstract double calculate(); | ||
|
||
public SearchMetric(final int k) { | ||
this.k = k; | ||
} | ||
|
||
public int getK() { | ||
return k; | ||
} | ||
|
||
} |
149 changes: 0 additions & 149 deletions
149
...ch-quality-evaluation-plugin/src/main/java/org/opensearch/eval/metrics/SearchMetrics.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.