Skip to content
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
May 11, 2015
3cffed4
Adding unit tests for argmax functions for Dense and Sparse vectors
May 12, 2015
df9538a
Added argmax to sparse vector and added unit test
May 12, 2015
4526acc
Merge branch 'master' of github.com:apache/spark into SPARK-7422
May 13, 2015
eeda560
Fixing SparseVector argmax function to ignore zero values while doing…
May 15, 2015
af17981
Initial work fixing bug that was made clear in pr
dittmarg May 22, 2015
f21dcce
commit
GeorgeDittmar May 25, 2015
b1f059f
Added comment before we start arg max calculation. Updated unit tests…
GeorgeDittmar May 29, 2015
3ee8711
Fixing corner case issue with zeros in the active values of the spars…
GeorgeDittmar Jun 1, 2015
ee1a85a
Cleaning up unit tests a bit and modifying a few cases
GeorgeDittmar Jun 1, 2015
d5b5423
Fixing code style and updating if logic on when to check for zero values
GeorgeDittmar Jun 9, 2015
ac53c55
changing dense vector argmax unit test to be one line call vs 2
GeorgeDittmar Jun 9, 2015
aa330e3
Fixing some last if else spacing issues
GeorgeDittmar Jun 9, 2015
f2eba2f
Cleaning up unit tests to be fewer lines
GeorgeDittmar Jun 9, 2015
b22af46
Fixing spaces between commas in unit test
GeorgeDittmar Jun 10, 2015
42341fb
refactoring arg max check to better handle zero values
GeorgeDittmar Jul 9, 2015
5fd9380
fixing style check error
GeorgeDittmar Jul 9, 2015
98058f4
Merge branch 'master' of github.com:apache/spark into SPARK-7422
GeorgeDittmar Jul 15, 2015
2ea6a55
Added MimaExcludes for Vectors.argmax
GeorgeDittmar Jul 15, 2015
127dec5
update argmax impl
mengxr Jul 17, 2015
3e0a939
Merge pull request #1 from mengxr/SPARK-7422
GeorgeDittmar Jul 18, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update argmax impl
  • Loading branch information
mengxr committed Jul 17, 2015
commit 127dec5d7aa536f70891dfce10d0fb56a3b57723
36 changes: 29 additions & 7 deletions mllib/src/main/scala/org/apache/spark/mllib/linalg/Vectors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -724,22 +724,44 @@ class SparseVector(
if (size == 0) {
-1
} else {
// Find the max active entry.
var maxIdx = indices(0)
var maxValue = values(0)

foreachActive { (i, v) =>
var maxJ = 0
var j = 1
val na = numActives
while (j < na) {
val v = values(j)
if (v > maxValue) {
maxIdx = i
maxValue = v
maxIdx = indices(j)
maxJ = j
}
j += 1
}

var k = 0
while (k < indices.length && indices(k) == k && values(k) != 0.0) {
k += 1
// If the max active entry is nonpositive and there exists inactive ones, find the first zero.
if (maxValue <= 0.0 && na < size) {
if (maxValue == 0.0) {
// If there exists an inactive entry before maxIdx, find it and return its index.
if (maxJ < maxIdx) {
var k = 0
while (k < maxJ && indices(k) == k) {
k += 1
}
maxIdx = k
}
} else {
// If the max active value is negative, find and return the first inactive index.
var k = 0
while (k < na && indices(k) == k) {
k += 1
}
maxIdx = k
}
}

if (maxValue <= 0.0 || k >= maxIdx) k else maxIdx
maxIdx
}
}
}
Expand Down