-
Notifications
You must be signed in to change notification settings - Fork 29k
[Spark-7422][MLLIB] Add argmax to Vector, SparseVector #6112
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
04677af
initial work on adding argmax to Vector and SparseVector
3cffed4
Adding unit tests for argmax functions for Dense and Sparse vectors
df9538a
Added argmax to sparse vector and added unit test
4526acc
Merge branch 'master' of github.com:apache/spark into SPARK-7422
eeda560
Fixing SparseVector argmax function to ignore zero values while doing…
af17981
Initial work fixing bug that was made clear in pr
dittmarg f21dcce
commit
GeorgeDittmar b1f059f
Added comment before we start arg max calculation. Updated unit tests…
GeorgeDittmar 3ee8711
Fixing corner case issue with zeros in the active values of the spars…
GeorgeDittmar ee1a85a
Cleaning up unit tests a bit and modifying a few cases
GeorgeDittmar d5b5423
Fixing code style and updating if logic on when to check for zero values
GeorgeDittmar ac53c55
changing dense vector argmax unit test to be one line call vs 2
GeorgeDittmar aa330e3
Fixing some last if else spacing issues
GeorgeDittmar f2eba2f
Cleaning up unit tests to be fewer lines
GeorgeDittmar b22af46
Fixing spaces between commas in unit test
GeorgeDittmar 42341fb
refactoring arg max check to better handle zero values
GeorgeDittmar 5fd9380
fixing style check error
GeorgeDittmar 98058f4
Merge branch 'master' of github.com:apache/spark into SPARK-7422
GeorgeDittmar 2ea6a55
Added MimaExcludes for Vectors.argmax
GeorgeDittmar 127dec5
update argmax impl
mengxr 3e0a939
Merge pull request #1 from mengxr/SPARK-7422
GeorgeDittmar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fixing code style and updating if logic on when to check for zero values
- Loading branch information
commit d5b5423522a1753b99dacd0597d8a929f37e5646
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -736,11 +736,9 @@ class SparseVector( | |
| } | ||
|
|
||
| // look for inactive values in case all active node values are negative | ||
| if(size != values.size && maxValue <= 0){ | ||
| if (size != values.size && maxValue <= 0){ | ||
| val firstInactiveIdx = calcFirstInactiveIdx(0) | ||
| if(maxValue == 0){ | ||
| if(firstInactiveIdx >= maxIdx) maxIdx else maxIdx = firstInactiveIdx | ||
| }else{ | ||
| if (!(maxValue == 0 && firstInactiveIdx >= maxIdx)){ | ||
| maxIdx = firstInactiveIdx | ||
| } | ||
| maxValue = 0 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not needed |
||
|
|
||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -91,22 +91,26 @@ class VectorsSuite extends FunSuite { | |
| val max = vec2.argmax | ||
| assert(max === 3) | ||
|
|
||
| val vec3 = Vectors.sparse(5,Array(2, 4),Array(1.0,-.7)) | ||
| val vec3 = Vectors.sparse(5,Array(2, 3, 4),Array(1.0, 0.0, -.7)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: spaces after comma. |
||
| val max2 = vec3.argmax | ||
| assert(max2 === 2) | ||
|
|
||
| // check for case that sparse vector is created with only negative values {0.0, 0.0,-1.0, -0.7, 0.0} | ||
| val vec4 = Vectors.sparse(5,Array(2, 3),Array(-1.0,-.7)) | ||
| val vec4 = Vectors.sparse(5,Array(2, 3),Array(-1.0, -.7)) | ||
| val max3 = vec4.argmax | ||
| assert(max3 === 0) | ||
|
|
||
| val vec5 = Vectors.sparse(11,Array(0, 3, 10),Array(-1.0,-.7,0.0)) | ||
| val vec5 = Vectors.sparse(11,Array(0, 3, 10),Array(-1.0, -.7, 0.0)) | ||
| val max4 = vec5.argmax | ||
| assert(max4 === 1) | ||
|
|
||
| val vec6 = Vectors.sparse(5,Array(0, 1, 3),Array(-1.0, 0.0, -.7)) | ||
| val vec6 = Vectors.sparse(11,Array(0, 1, 2),Array(-1.0, -.7, 0.0)) | ||
| val max5 = vec6.argmax | ||
| assert(max5 === 1) | ||
| assert(max5 === 2) | ||
|
|
||
| val vec7 = Vectors.sparse(5,Array(0, 1, 3),Array(-1.0, 0.0, -.7)) | ||
| val max6 = vec7.argmax | ||
| assert(max6 === 1) | ||
|
|
||
| var vec8 = Vectors.sparse(5,Array(1, 2),Array(0.0, -1.0)) | ||
| val max7 = vec8.argmax | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think this line can be removed, since only maxIdx is used.
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.
I more kept it in there for clarity incase anyone is debugging through the code and can more easily understand what the associated idx and val are. But i can remove if its just too much clutter.