Github user nakul02 commented on a diff in the pull request:

    https://github.com/apache/spark/pull/9756#discussion_r46596717
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/mllib/util/LinearDataGenerator.scala ---
    @@ -131,35 +131,30 @@ object LinearDataGenerator {
           eps: Double,
           sparsity: Double): Seq[LabeledPoint] = {
         require(0.0 <= sparsity && sparsity <= 1.0)
    -    val rnd = new Random(seed)
    -    val x = Array.fill[Array[Double]](nPoints)(
    -      Array.fill[Double](weights.length)(rnd.nextDouble()))
    -
    -    val sparseRnd = new Random(seed)
    -    x.foreach { v =>
    -      var i = 0
    -      val len = v.length
    -      while (i < len) {
    -        if (sparseRnd.nextDouble() < sparsity) {
    -          v(i) = 0.0
    -        } else {
    -          v(i) = (v(i) - 0.5) * math.sqrt(12.0 * xVariance(i)) + xMean(i)
    -        }
    -        i += 1
    -      }
    -    }
     
    -    val y = x.map { xi =>
    -      blas.ddot(weights.length, xi, 1, weights, 1) + intercept + eps * 
rnd.nextGaussian()
    -    }
    -
    -    y.zip(x).map { p =>
    -      if (sparsity == 0.0) {
    +    val rnd = new Random(seed)
    +    if (sparsity == 0.0) {
    +      (0 until nPoints).map { _ =>
    +        val features = Vectors.dense(weights.indices.map { i =>
    +          (rnd.nextDouble() - 0.5) * math.sqrt(12.0 * xVariance(i)) + 
xMean(i)
    --- End diff --
    
    The way the array is built for dense and sparse features is different. I 
suspect it might be more clunky to try and find something common between them 
to refactor something out into a local def.


---
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]

Reply via email to