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

    https://github.com/apache/spark/pull/9756#discussion_r46595367
  
    --- 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)
    +        }.toArray)
    +        val label = BLAS.dot(Vectors.dense(weights), features) +
    +          intercept + eps * rnd.nextGaussian()
             // Return LabeledPoints with DenseVector
    -        LabeledPoint(p._1, Vectors.dense(p._2))
    -      } else {
    +        LabeledPoint(label, features)
    +      }
    +    } else {
    +      val sparseRnd = new Random(seed)
    --- End diff --
    
    The original code uses two RNGs. The sparse RNG is at line 138 in the 
original file.


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