Skip to content

Instantly share code, notes, and snippets.

@cqfd
Created June 8, 2018 13:04
Show Gist options
  • Save cqfd/54f17d0363749d94883d9938d860c32c to your computer and use it in GitHub Desktop.
Save cqfd/54f17d0363749d94883d9938d860c32c to your computer and use it in GitHub Desktop.
(Attempt at) the Kumaraswamy distribution in Rainier.
// Doesn't work yet!
object Kumaraswamy {
def apply(a: Real, b: Real): Continuous = new Continuous {
def realLogDensity(x: Real): Real =
If(x <= 0,
Real.zero.log,
If(x >= 1, Real.zero.log, (a - 1) * x.log + (b - 1) * (1 - x.pow(a))))
def param: RandomVariable[Real] = {
for {
u <- Uniform(0, 1).param
} yield (1 - (1 - u).pow(1.0 / a)).pow(1.0 / b)
}
val generator: Generator[Double] = Generator.from { (r, n) =>
val u = r.standardUniform
math.pow(1 - math.pow(1 - u, 1 / n.toDouble(b)), 1 / n.toDouble(a))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment