
Rainier
Rainier provides a high-performance Scala API for bayesian inference via Markov Chain Monte Carlo.
Rainier supports fixed-structure generative models with continuous parameters. Models are built using idiomatic, functional Scala to compose primitive distributions and mathematical transformations. Once built, you can condition the model on observed data to infer a posterior distribution over the parameter values, and then use that posterior distribution to generate decisions and predictions.
Underlying this high-level API is a static, TensorFlow-style compute graph with auto-differentiation and very fast CPU-based execution.
Rainier is implemented in pure Scala, with minimal external dependencies and no JNI libs, and as such is convenient to deploy, including to Spark or Hadoop clusters.
Inference is based on variants of the Hamiltonian Monte Carlo sampler; similar to, and targeting the same types of models as, both Stan and PyMC3. Depending on your background, you might think of Rainier as aspiring to be either "Stan, but on the JVM", or "TensorFlow, but for small data".
Example
Here's what it looks like to fit a simple linear regression in Rainier:
val xs: List[(Double, Double, Double)] = ???
val ys: List[Double] = ???
val sigma = Exponential(1).latent
val alpha = Normal(0,1).latent
val betas = Normal(0,1).latentVec(3)
val model = Model.observe(ys, Vec.from(xs).map{
case (u, v, w) =>
val mu = alpha + Vec(u,v,w).dot(betas)
Normal(mu, sigma)
})
Getting Started and Documentation
There's a detailed overview and reference documentation at rainier.fit.
Performance and Scale
Rainier requires that all of the observations or training data for a given model fit comfortably into RAM on a single machine. It does not make use of GPUs or of SIMD instructions.
Within those constraints, however, it is extremely fast. Rainier takes advantage of knowing all of your data ahead of time by aggressively precomputing as much as it can, which can be a significant practical benefit relative to systems that compile a data-agnostic model. It produces optimized, unboxed, JIT-friendly JVM bytecode for all numerical calculations. This compilation happens in-process and is fast enough for interactive use at a REPL.