-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding L2 norm technique #236
Adding L2 norm technique #236
Conversation
Signed-off-by: Martin Gaievski <[email protected]>
Signed-off-by: Martin Gaievski <[email protected]>
Codecov Report
@@ Coverage Diff @@
## feature/normalization #236 +/- ##
===========================================================
- Coverage 85.95% 82.43% -3.53%
- Complexity 310 323 +13
===========================================================
Files 24 26 +2
Lines 904 979 +75
Branches 137 153 +16
===========================================================
+ Hits 777 807 +30
- Misses 67 108 +41
- Partials 60 64 +4
|
.../java/org/opensearch/neuralsearch/processor/normalization/L2ScoreNormalizationTechnique.java
Outdated
Show resolved
Hide resolved
.../java/org/opensearch/neuralsearch/processor/normalization/L2ScoreNormalizationTechnique.java
Outdated
Show resolved
Hide resolved
.../java/org/opensearch/neuralsearch/processor/normalization/L2ScoreNormalizationTechnique.java
Outdated
Show resolved
Hide resolved
.../java/org/opensearch/neuralsearch/processor/normalization/L2ScoreNormalizationTechnique.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Martin Gaievski <[email protected]>
public float combine(final float[] scores) { | ||
float combinedScore = 0.0f; | ||
float weights = 0; | ||
for (int indexOfSubQuery = 0; indexOfSubQuery < scores.length; indexOfSubQuery++) { | ||
float score = scores[indexOfSubQuery]; | ||
if (score >= 0.0) { | ||
float weight = getWeightForSubQuery(indexOfSubQuery); | ||
score = score * weight; | ||
combinedScore += score; | ||
weights += weight; | ||
} | ||
} | ||
if (weights == 0.0f) { | ||
return ZERO_SCORE; | ||
} | ||
return combinedScore / weights; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
weighted harmonic mean = sum(wi) / sum(1/(wi*si))
https://en.wikipedia.org/wiki/Harmonic_mean
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @HenryL27 , that's what I'm working now and it will be a new PR for harmonic mean and weighted geometric combination. Probably checked in this class incidentally in a half-ready form.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, no worries. Thanks!
Description
Adding L2 normalization technique for normalization processor. Essentially L2 norm is "score" divided by square root of sum of score squares (more details here). Example of pipeline with processor config:
Issues Resolved
#228, part of solution for #126
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.