-
Notifications
You must be signed in to change notification settings - Fork 29k
[Spark-11968][ML][MLLIB]Optimize MLLIB ALS recommendForAll #17742
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
Changes from 1 commit
14cdbf6
f607e6c
ae03124
2fd97a0
206a023
8eab55b
a5261b7
44a4f74
17df4cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -277,39 +277,38 @@ object MatrixFactorizationModel extends Loader[MatrixFactorizationModel] { | |
| num: Int): RDD[(Int, Array[(Int, Double)])] = { | ||
| val srcBlocks = blockify(rank, srcFeatures) | ||
| val dstBlocks = blockify(rank, dstFeatures) | ||
| val ratings = srcBlocks.cartesian(dstBlocks).flatMap { | ||
| case (users, items) => | ||
| val m = users.size | ||
| val n = math.min(items.size, num) | ||
| val ratings = srcBlocks.cartesian(dstBlocks).flatMap { case (srcIter, dstIter) => | ||
| val m = srcIter.size | ||
| val n = math.min(dstIter.size, num) | ||
| val output = new Array[(Int, (Int, Double))](m * n) | ||
| var j = 0 | ||
| users.foreach (user => { | ||
| srcIter.foreach { case (srcId, srcFactor) => | ||
| def order(a: (Int, Double)) = a._2 | ||
| val pq: BoundedPriorityQueue[(Int, Double)] = | ||
|
||
| new BoundedPriorityQueue[(Int, Double)](n)(Ordering.by(order)) | ||
|
||
| items.foreach (item => { | ||
| dstIter.foreach { case (dstId, dstFactor) => | ||
| /** | ||
| * blas.ddot (F2jBLAS) is the same performance with the following code. | ||
| * the performace of blas.ddot with NativeBLAS is very bad. | ||
| * blas.ddot (F2jBLAS) is about 10% improvement comparing with linalg.dot. | ||
| * val rate = blas.ddot(rank, user._2, 1, item._2, 1) | ||
|
||
| */ | ||
| var rate: Double = 0 | ||
| var score: Double = 0 | ||
| var k = 0 | ||
| while(k < rank) { | ||
| rate += user._2(k) * item._2(k) | ||
| while (k < rank) { | ||
| score += srcFactor(k) * dstFactor(k) | ||
| k += 1 | ||
| } | ||
| pq += ((item._1, rate)) | ||
| }) | ||
| pq += ((dstId, score)) | ||
| } | ||
| val pqIter = pq.iterator | ||
| var i = 0 | ||
| while(i < n) { | ||
| output(j + i) = (user._1, pqIter.next()) | ||
| while (i < n) { | ||
| output(j + i) = (srcId, pqIter.next()) | ||
| i += 1 | ||
| } | ||
| j += n | ||
| }) | ||
| } | ||
| output.toSeq | ||
| } | ||
| ratings.topByKey(num)(Ordering.by(_._2)) | ||
|
|
||
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'd like to more detail to the doc string comment for this method to explain the approach used for efficiency.