Github user tgaloppo commented on a diff in the pull request:
https://github.com/apache/spark/pull/4459#discussion_r24326410
--- Diff:
mllib/src/main/scala/org/apache/spark/mllib/clustering/GaussianMixture.scala ---
@@ -215,20 +217,29 @@ private object ExpectationSum {
def add(
weights: Array[Double],
dists: Array[MultivariateGaussian])
- (sums: ExpectationSum, x: BreezeVector[Double]): ExpectationSum = {
+ (sums: ExpectationSum, x: BV[Double]): ExpectationSum = {
val p = weights.zip(dists).map {
case (weight, dist) => MLUtils.EPSILON + weight * dist.pdf(x)
}
val pSum = p.sum
sums.logLikelihood += math.log(pSum)
- val xxt = x * new Transpose(x)
var i = 0
+ val isSparse = x match {
+ case _: BSV[Double] => true
+ case _: BDV[Double] => false
+ }
while (i < sums.k) {
p(i) /= pSum
sums.weights(i) += p(i)
sums.means(i) += x * p(i)
- BLAS.syr(p(i), Vectors.fromBreeze(x).asInstanceOf[DenseVector],
- Matrices.fromBreeze(sums.sigmas(i)).asInstanceOf[DenseMatrix])
+ if (isSparse){
+ BLAS.syr(p(i), Vectors.fromBreeze(x).asInstanceOf[SparseVector],
+ Matrices.fromBreeze(sums.sigmas(i)).asInstanceOf[DenseMatrix])
+ }
+ else {
+ BLAS.syr(p(i), Vectors.fromBreeze(x).asInstanceOf[DenseVector],
+ Matrices.fromBreeze(sums.sigmas(i)).asInstanceOf[DenseMatrix])
+ }
--- End diff --
@MechCoder Indeed, you have already overloaded the syr() method, so you
just need to add another one of the form:
def syr(alpha: Double, x: Vector, A: DenseMatrix) {
x match {
case dv: DenseVector => syr(alpha, dv, A)
case sv: SparseVector => syr(alpha, sv, A)
case _ => throw new IllegalArgumentException(s"syr: unsupported
vector type ${x.getClass}")
}
}
...or something along those lines... then given the overloads
def syr(alpha: Double, x: DenseVector, A: DenseMatrix) ...
and
def syr(alpha: Double, x: SparseVector, A: DenseMatrix) ...
it should be all set.
---
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]