Created
December 2, 2015 18:04
-
-
Save bioball/fab37d4fff6eef053a5f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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