Github user mengxr commented on a diff in the pull request:
https://github.com/apache/spark/pull/6383#discussion_r30991539
--- Diff:
mllib/src/main/scala/org/apache/spark/mllib/stat/KernelDensity.scala ---
@@ -86,20 +86,20 @@ class KernelDensity extends Serializable {
val n = points.length
// This gets used in each Gaussian PDF computation, so compute it up
front
val logStandardDeviationPlusHalfLog2Pi = math.log(bandwidth) + 0.5 *
math.log(2 * math.Pi)
- val (densities, count) = sample.aggregate((new Array[Double](n), 0L))(
+ val densities = sample.aggregate(new Array[Double](n))(
(x, y) => {
var i = 0
while (i < n) {
- x._1(i) += normPdf(y, bandwidth,
logStandardDeviationPlusHalfLog2Pi, points(i))
+ x(i) += normPdf(y, bandwidth,
logStandardDeviationPlusHalfLog2Pi, points(i))
i += 1
}
- (x._1, n)
+ x
},
(x, y) => {
- blas.daxpy(n, 1.0, y._1, 1, x._1, 1)
- (x._1, x._2 + y._2)
+ blas.daxpy(n, 1.0, y, 1, x, 1)
+ x
})
- blas.dscal(n, 1.0 / count, densities, 1)
+ blas.dscal(n, 1.0 / sample.count, densities, 1)
--- End diff --
Please aggregate densities and count in a single pass.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]