Github user srowen commented on the pull request:
https://github.com/apache/spark/pull/12299#issuecomment-215065214
I actually implemented the idea above and it turns out to be slower at a
scale of about 5000 features already. My quick test locally:
```
import org.apache.spark._
import org.apache.spark.mllib.random._
import org.apache.spark.mllib.linalg._
import org.apache.spark.mllib.linalg.distributed._
import scala.util.Random
def compute(rows: Int, cols: Int, sparsity: Double, sc: SparkContext): Unit
= {
val vectors = sc.parallelize(0 until rows, 8).mapPartitions { rowNums =>
val random = new Random()
rowNums.map { n =>
val indices = (0 until cols).filter(c => random.nextDouble() <
sparsity).toArray
val values = indices.map(i => random.nextDouble())
new SparseVector(cols, indices, values).asInstanceOf[Vector]
}
}
new RowMatrix(vectors, rows, cols).computeCovariance
}
compute(10000, 5000, 0.01, sc)
```
Current implementation took about 1.9 minutes, whereas modifying it to
compute as in https://github.com/apache/spark/pull/12299#issuecomment-208873482
took 2.8 minutes. (The original, less accurate version takes seconds). I
presume that paying the cost of creating a dense centered vector ends up being
overshadowed by the efficiency gain in pushing the computation down to BLAS
then.
I don't have brighter ideas at this point.
At least, the following two changes are uncontroversial:
- improve the computation of the mean using the standard stats class
- improve the situation for dense vectors
The question is: take the performance hit and fix covariance for large
sparse vectors? or leave it as-is as a known issue? any opinions?
---
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]