Skip to content

Instantly share code, notes, and snippets.

@bioball
Created December 2, 2015 18:04
Show Gist options
  • Save bioball/fab37d4fff6eef053a5f to your computer and use it in GitHub Desktop.
Save bioball/fab37d4fff6eef053a5f to your computer and use it in GitHub Desktop.
package com.typeclassified.cssr
import breeze.linalg.DenseVector
import com.typeclassified.cssr.parse.ParseNode
import scala.collection.mutable.ArrayBuffer
object CSSRState {
def apply(histories: ArrayBuffer[ParseNode] = ArrayBuffer()) = new CSSRState(histories)
}
class CSSRState(val histories: ArrayBuffer[ParseNode]) {
def addHistory(h: ParseNode): CSSRState = CSSRState(histories :+ h)
def rmHistory(x: ParseNode): CSSRState = CSSRState(histories.filter(y => y != x))
def frequency: DenseVector[Double] = histories.foldRight(frequency)((history, totalFreq) => totalFreq :+ history.frequency)
def totalCounts: Int = frequency.foldRight(0d)(_ + _).toInt
def normalDistribution: DenseVector[Double] = frequency :/ totalCounts.toDouble
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment