Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- val lambda = 1
- def learnTheta(d: List[(String, Double)], c: Boolean, topic: String, step: Double) = {
- var thetaTopic = thetas(topic).theta
- var y = 0
- if (c) y = 1
- else y = -1
- val innerProduct = d.par.map(t => t._2 * thetaTopic(t._1)).sum
- val multBy = 1 - 1.0 / step
- thetaTopic ++= thetaTopic.par.map(t => t._1 -> t._2 * multBy).toList
- val margin = 1.0 - (y * innerProduct)
- if (margin > 0) {
- val tmp = (1.0 / (lambda * step)) * y
- thetaTopic ++= d.par.map(t => t._1 -> (thetaTopic(t._1) + t._2 * tmp)).toList
- }
- }
Add Comment
Please, Sign In to add comment