Fixed score calculation to use selected bits in the vector. Addresses #2155
This commit is contained in:
parent
590d3c468b
commit
296b193bb5
|
@ -114,13 +114,13 @@ public final class EmpiMatchOutcome {
|
|||
public Double getNormalizedScore() {
|
||||
if (vector == 0) {
|
||||
return 0.0;
|
||||
} else if (score > vector) {
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
double retVal = score / vector;
|
||||
double retVal = score / Long.bitCount(vector);
|
||||
if (retVal < 0) {
|
||||
retVal = 0.0;
|
||||
} else if (retVal > 1.0) {
|
||||
return 1.0;
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
|
|
@ -6,22 +6,35 @@ import static org.junit.jupiter.api.Assertions.*;
|
|||
|
||||
class EmpiMatchOutcomeTest {
|
||||
|
||||
public static final double DELTA = 0.0001;
|
||||
|
||||
@Test
|
||||
void testNormalizedScore() {
|
||||
EmpiMatchOutcome outcome = new EmpiMatchOutcome(0l, 0.0);
|
||||
assertEquals(0.0, outcome.getNormalizedScore());
|
||||
|
||||
outcome = new EmpiMatchOutcome(10l, 10.0);
|
||||
assertEquals(1.0, outcome.getNormalizedScore());
|
||||
outcome = new EmpiMatchOutcome(selectBits(10), 10.0);
|
||||
assertEquals(1.0, outcome.getNormalizedScore(), DELTA);
|
||||
|
||||
outcome = new EmpiMatchOutcome(10l, -10.0);
|
||||
outcome = new EmpiMatchOutcome(selectBits(10), -10.0);
|
||||
assertEquals(0.0, outcome.getNormalizedScore());
|
||||
|
||||
outcome = new EmpiMatchOutcome(3l, 2.0);
|
||||
assertEquals(2.0 / 3.0, outcome.getNormalizedScore(), 0.0001);
|
||||
outcome = new EmpiMatchOutcome(selectBits(3), 2.0);
|
||||
assertEquals(2.0 / 3.0, outcome.getNormalizedScore(), DELTA);
|
||||
|
||||
outcome = new EmpiMatchOutcome(5l, 19.0);
|
||||
outcome = new EmpiMatchOutcome(selectBits(8), 4.0);
|
||||
assertEquals(4.0 / 8.0, outcome.getNormalizedScore(), DELTA);
|
||||
|
||||
outcome = new EmpiMatchOutcome(selectBits(5), 19.0);
|
||||
assertEquals(1.0, outcome.getNormalizedScore());
|
||||
}
|
||||
|
||||
private long selectBits(int theN) {
|
||||
long retVal = 0;
|
||||
for (int i = 0; i < theN; i++) {
|
||||
retVal |= (1 << i);
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue