Skip to content

Commit

Permalink
Make in-place variables vals, fix BLAS error
Browse files Browse the repository at this point in the history
  • Loading branch information
Feynman Liang committed Jul 21, 2015
1 parent 7f62a55 commit 78b0f5a
Showing 1 changed file with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -385,28 +385,30 @@ final class OnlineLDAOptimizer extends LDAOptimizer {
case v => throw new IllegalArgumentException("Online LDA does not support vector type "
+ v.getClass)
}
if (!ids.isEmpty) {

// Initialize the variational distribution q(theta|gamma) for the mini-batch
val gammad: BDV[Double] =
new Gamma(gammaShape, 1.0 / gammaShape).samplesVector(k) // K
val expElogthetad: BDV[Double] = exp(digamma(gammad) - digamma(sum(gammad))) // K
val expElogbetad: BDM[Double] = expElogbeta(ids, ::).toDenseMatrix // ids * K

val phinorm: BDV[Double] = expElogbetad * expElogthetad :+ 1e-100 // ids
var meanchange = 1D
val ctsVector = new BDV[Double](cts) // ids

// Iterate between gamma and phi until convergence
while (meanchange > 1e-3) {
val lastgamma = gammad.copy
// K K * ids ids
gammad := (expElogthetad :* (expElogbetad.t * (ctsVector :/ phinorm))) :+ alpha
expElogthetad := exp(digamma(gammad) - digamma(sum(gammad)))
phinorm := expElogbetad * expElogthetad :+ 1e-100
meanchange = sum(abs(gammad - lastgamma)) / k
}

// Initialize the variational distribution q(theta|gamma) for the mini-batch
var gammad: BDV[Double] =
new Gamma(gammaShape, 1.0 / gammaShape).samplesVector(k) // K
val expElogthetad: BDV[Double] = exp(digamma(gammad) - digamma(sum(gammad))) // K
val expElogbetad: BDM[Double] = expElogbeta(ids, ::).toDenseMatrix // ids * K

var phinorm: BDV[Double] = expElogbetad * expElogthetad :+ 1e-100 // ids
var meanchange = 1D
val ctsVector = new BDV[Double](cts) // ids

// Iterate between gamma and phi until convergence
while (meanchange > 1e-3) {
val lastgamma = gammad.copy
// K K * ids ids
gammad := (expElogthetad :* (expElogbetad.t * (ctsVector :/ phinorm))) :+ alpha
expElogthetad := exp(digamma(gammad) - digamma(sum(gammad)))
phinorm := expElogbetad * expElogthetad :+ 1e-100
meanchange = sum(abs(gammad - lastgamma)) / k
stat(::, ids) := expElogthetad.asDenseMatrix.t * (ctsVector :/ phinorm).asDenseMatrix
}

stat(::, ids) := expElogthetad.asDenseMatrix.t * (ctsVector :/ phinorm).asDenseMatrix
}
Iterator(stat)
}
Expand Down

0 comments on commit 78b0f5a

Please sign in to comment.