diff --git a/src/main/java/com/sparrowrecsys/offline/spark/embedding/Embedding.scala b/src/main/java/com/sparrowrecsys/offline/spark/embedding/Embedding.scala index 7f959dc0..f73f0a20 100644 --- a/src/main/java/com/sparrowrecsys/offline/spark/embedding/Embedding.scala +++ b/src/main/java/com/sparrowrecsys/offline/spark/embedding/Embedding.scala @@ -162,8 +162,10 @@ object Embedding { val probDistribution = transitionMatrix(curElement) val randomDouble = Random.nextDouble() + var accumulateProb: Double = 0D breakable { for ((item, prob) <- probDistribution) { - if (randomDouble >= prob){ + accumulateProb += prob + if (accumulateProb >= randomDouble){ curElement = item break }