Skip to content

Commit

Permalink
Bug fix in generation of sparse vector.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nakul Jindal committed Nov 24, 2015
1 parent b5038e8 commit 70917f8
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ object LinearDataGenerator {

val rnd = new Random(seed)
val rndG = new Random(seed)
if (sparsity <= 0.0) {
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)
Expand All @@ -148,7 +148,7 @@ object LinearDataGenerator {
val sparseRnd = new Random(seed)
(0 until nPoints).map { _ =>
val (values, indices) = (0 until weights.length).filter { _ =>
sparseRnd.nextDouble() >= sparsity }.map { i =>
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)
Expand Down

0 comments on commit 70917f8

Please sign in to comment.