Skip to content

Commit

Permalink
Added clipping to zscore
Browse files Browse the repository at this point in the history
Signed-off-by: Owais <[email protected]>
  • Loading branch information
owaiskazi19 committed Feb 11, 2025
1 parent 404eadc commit 49e46c4
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class ZScoreNormalizationTechnique implements ScoreNormalizationTechnique

public static final String TECHNIQUE_NAME = "z_score";
private static final float SINGLE_RESULT_SCORE = 1.0f;
private static final float MIN_BOUND = -3.0f;
private static final float MAX_BOUND = 3.0f;

@Override
public void normalize(final List<CompoundTopDocs> queryTopDocs) {
Expand Down Expand Up @@ -153,7 +155,13 @@ private static float normalizeSingleScore(final float score, final float standar
if (Floats.compare(mean, score) == 0) {
return SINGLE_RESULT_SCORE;
}
return (score - mean) / standardDeviation;
float normalizedScore = (score - mean) / standardDeviation;
if (normalizedScore < MIN_BOUND) {
return MIN_BOUND;
} else if (normalizedScore > MAX_BOUND) {
return MAX_BOUND;
}
return normalizedScore;
}

}

0 comments on commit 49e46c4

Please sign in to comment.