All Downloads are FREE. Search and download functionalities are using the official Maven repository.

thinkbayes.utils.Beta.scala Maven / Gradle / Ivy

The newest version!
package thinkbayes.utils

import scala.math._
import thinkbayes._

class Beta(var alpha: Double = 1.0, var beta: Double = 1.0) extends BoundedPdf {
  def density(x: Double) = pow(x, alpha - 1) * pow(1 - x, beta - 1)
  def upperBound: Double = 0.0
  def lowerBound: Double = 1.0

  def update(data: Boolean) {
    if (data) alpha += 1.0 else beta += 1.0
  }

  def updateSet(dataset: TraversableOnce[Boolean]) {
    val (trues, falses) = dataset.foldLeft((0, 0)) {
      case ((t, f), data) => if (data) (t + 1, f) else (t, f + 1)
    }
    alpha += trues
    beta += falses
  }

  def updateSet(dataCounts: (Int, Int)) {
    alpha += dataCounts._1
    beta += dataCounts._2
  }

  def mean = alpha / (alpha + beta)
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy