spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nakul02 <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-11439][ML] Optimization of creating spa...
Date Tue, 24 Nov 2015 01:43:39 GMT
Github user nakul02 commented on a diff in the pull request:

    https://github.com/apache/spark/pull/9756#discussion_r45688235
  
    --- Diff: mllib/src/main/scala/org/apache/spark/mllib/util/LinearDataGenerator.scala ---
    @@ -131,39 +131,36 @@ 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)
    +    val rndG = new Random(seed)
    +    if (sparsity <= 0.0) {
    +      (0 until nPoints).map { _ =>
    +        val features = Vectors.dense((0 until weights.length).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 * rndG.nextGaussian()
             // Return LabeledPoints with DenseVector
    -        LabeledPoint(p._1, Vectors.dense(p._2))
    -      } else {
    +        LabeledPoint(label, features)
    +      }
    +    } else {
    +      val sparseRnd = new Random(seed)
    +      (0 until nPoints).map { _ =>
    +        val (values, indices) = (0 until weights.length).filter { _ =>
    +          sparseRnd.nextDouble() >= sparsity }.map { i =>
    +          ((rnd.nextDouble() - 0.5) * math.sqrt(12.0 * xVariance(i)) + xMean(i), i)
    +        }.unzip
    +        val features = Vectors.sparse(weights.length, indices.toArray, values.toArray)
    +        val label = BLAS.dot(Vectors.dense(weights), features) +
    +          intercept + eps * rndG.nextGaussian()
    --- End diff --
    
    I am working on this now. Regenerating results from the tests.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message