Skip to content

Commit

Permalink
Make random seed an argument
Browse files Browse the repository at this point in the history
  • Loading branch information
freeman-lab committed Oct 29, 2014
1 parent 44050a9 commit 9cfc301
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,19 @@ class StreamingKMeans(
this
}

/** Initialize random centers, requiring only the number of dimensions. */
def setRandomCenters(d: Int): this.type = {
val initialCenters = (0 until k).map(_ => Vectors.dense(Array.fill(d)(nextGaussian()))).toArray
val clusterCounts = Array.fill(this.k)(0).map(_.toLong)
/** Initialize random centers, requiring only the number of dimensions.
*
* @param dim Number of dimensions
* @param seed Random seed
* */
def setRandomCenters(dim: Int, seed: Long = Utils.random.nextLong): this.type = {

val random = Utils.random
random.setSeed(seed)

val initialCenters = (0 until k)
.map(_ => Vectors.dense(Array.fill(dim)(random.nextGaussian()))).toArray
val clusterCounts = new Array[Long](this.k)
this.model = new StreamingKMeansModel(initialCenters, clusterCounts)
this
}
Expand Down

0 comments on commit 9cfc301

Please sign in to comment.