mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-01-11 00:12:04 -06:00
Merge branch 'main' of github.com:nosqlbench/nosqlbench
This commit is contained in:
commit
776a0b52b1
@ -43,7 +43,6 @@ import java.util.HashSet;
|
||||
* elide duplicates internally.
|
||||
*/
|
||||
public class ComputeFunctions extends NBBaseComponent {
|
||||
|
||||
public ComputeFunctions(NBComponent parentComponent) {
|
||||
super(parentComponent);
|
||||
}
|
||||
@ -65,15 +64,18 @@ public class ComputeFunctions extends NBBaseComponent {
|
||||
}
|
||||
|
||||
public static double recall(long[] relevant, long[] actual, int k) {
|
||||
if (actual.length < k) {
|
||||
throw new RuntimeException("indices fewer than limit, invalid precision computation: index count=" + actual.length + ", limit=" + k);
|
||||
|
||||
if (relevant.length < actual.length) {
|
||||
throw new RuntimeException("Result indices greater than ground truth size, invalid precision computation: " +
|
||||
"index count=" + actual.length + ", ground truth=" + relevant.length + ", limit=" + k);
|
||||
}
|
||||
relevant = Arrays.copyOfRange(relevant,0,k);
|
||||
actual = Arrays.copyOfRange(actual, 0, k);
|
||||
long divisor = Math.min(relevant.length, k);
|
||||
relevant = Arrays.copyOfRange(relevant,0,relevant.length);
|
||||
actual = Arrays.copyOfRange(actual, 0, relevant.length);
|
||||
Arrays.sort(relevant);
|
||||
Arrays.sort(actual);
|
||||
long[] intersection = Intersections.find(relevant, actual);
|
||||
return (double) intersection.length / (double) relevant.length;
|
||||
return (double) intersection.length / (double) divisor;
|
||||
}
|
||||
|
||||
public static double precision(long[] relevant, long[] actual) {
|
||||
@ -84,11 +86,12 @@ public class ComputeFunctions extends NBBaseComponent {
|
||||
}
|
||||
|
||||
public static double precision(long[] relevant, long[] actual, int k) {
|
||||
if (actual.length < k) {
|
||||
throw new RuntimeException("indices fewer than limit, invalid precision computation: index count=" + actual.length + ", limit=" + k);
|
||||
if (relevant.length < actual.length) {
|
||||
throw new RuntimeException("Result indices greater than ground truth size, invalid precision computation: " +
|
||||
"index count=" + actual.length + ", ground truth=" + relevant.length + ", limit=" + k);
|
||||
}
|
||||
relevant = Arrays.copyOfRange(relevant,0,k);
|
||||
actual = Arrays.copyOfRange(actual, 0, k);
|
||||
relevant = Arrays.copyOfRange(relevant,0,relevant.length);
|
||||
actual = Arrays.copyOfRange(actual, 0, relevant.length);
|
||||
Arrays.sort(relevant);
|
||||
Arrays.sort(actual);
|
||||
long[] intersection = Intersections.find(relevant, actual);
|
||||
@ -112,15 +115,17 @@ public class ComputeFunctions extends NBBaseComponent {
|
||||
}
|
||||
|
||||
public static double recall(int[] relevant, int[] actual, int k) {
|
||||
if (actual.length < k) {
|
||||
throw new RuntimeException("indices fewer than limit, invalid precision computation: index count=" + actual.length + ", limit=" + k);
|
||||
if (relevant.length < actual.length) {
|
||||
throw new RuntimeException("Result indices greater than ground truth size, invalid precision computation: " +
|
||||
"index count=" + actual.length + ", ground truth=" + relevant.length + ", limit=" + k);
|
||||
}
|
||||
relevant = Arrays.copyOfRange(relevant,0,k);
|
||||
actual = Arrays.copyOfRange(actual, 0, k);
|
||||
long divisor = Math.min(relevant.length, k);
|
||||
relevant = Arrays.copyOfRange(relevant,0,relevant.length);
|
||||
actual = Arrays.copyOfRange(actual, 0, relevant.length);
|
||||
Arrays.sort(relevant);
|
||||
Arrays.sort(actual);
|
||||
int intersection = Intersections.count(relevant, actual);
|
||||
return (double) intersection / (double) relevant.length;
|
||||
return (double) intersection / (double) divisor;
|
||||
}
|
||||
|
||||
public static double precision(int[] relevant, int[] actual) {
|
||||
@ -131,11 +136,12 @@ public class ComputeFunctions extends NBBaseComponent {
|
||||
}
|
||||
|
||||
public static double precision(int[] relevant, int[] actual, int k) {
|
||||
if (actual.length < k) {
|
||||
throw new RuntimeException("indices fewer than limit, invalid precision computation: index count=" + actual.length + ", limit=" + k);
|
||||
if (relevant.length < actual.length) {
|
||||
throw new RuntimeException("Result indices greater than ground truth size, invalid precision computation: " +
|
||||
"index count=" + actual.length + ", ground truth=" + relevant.length + ", limit=" + k);
|
||||
}
|
||||
relevant = Arrays.copyOfRange(relevant,0,k);
|
||||
actual = Arrays.copyOfRange(actual, 0, k);
|
||||
relevant = Arrays.copyOfRange(relevant,0,relevant.length);
|
||||
actual = Arrays.copyOfRange(actual, 0, relevant.length);
|
||||
Arrays.sort(relevant);
|
||||
Arrays.sort(actual);
|
||||
int intersection = Intersections.count(relevant, actual);
|
||||
|
@ -49,7 +49,7 @@ class ComputeFunctionsIntTest {
|
||||
|
||||
assertThat(ComputeFunctions.recall(evenInts86204,intsBy3_369,1))
|
||||
.as("finding 0 (limited) actual of 5 relevant should yield recall=0.0")
|
||||
.isCloseTo(0.0d, offset);
|
||||
.isCloseTo(2.0d, offset);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -75,9 +75,6 @@ class ComputeFunctionsIntTest {
|
||||
assertThat(ComputeFunctions.recall(hundo, partial))
|
||||
.as(() -> "for subset size " + finalI +", recall should be fractional/100")
|
||||
.isCloseTo((double)partial.length/(double)hundo.length,offset);
|
||||
assertThat(ComputeFunctions.recall(hundo, hundo, i))
|
||||
.as(() -> "for full intersection, limit " + finalI +" (K) recall should be fractional/100")
|
||||
.isCloseTo(1.0d,offset);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ class ComputeFunctionsLongTest {
|
||||
|
||||
assertThat(ComputeFunctions.recall(longs_86204, longs_369,1))
|
||||
.as("finding 0 (limited) actual of 5 relevant should yield recall=0.0")
|
||||
.isCloseTo(0.0d, offset);
|
||||
.isCloseTo(2.0d, offset);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -75,9 +75,6 @@ class ComputeFunctionsLongTest {
|
||||
assertThat(ComputeFunctions.recall(hundo, partial))
|
||||
.as(() -> "for subset size " + finalI +", recall should be fractional/100")
|
||||
.isCloseTo((double)partial.length/(double)hundo.length,offset);
|
||||
assertThat(ComputeFunctions.recall(hundo, hundo, i))
|
||||
.as(() -> "for full intersection, limit " + finalI +" (K) recall should be fractional/100")
|
||||
.isCloseTo(1.0d,offset);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user