README.md

RWebPPL

Travis-CI Build Status

RWebPPL is an R package providing an interface to WebPPL, a probabilistic programming language.

Installation

System requirements

devtools::install_github("mhtess/rwebppl")

RWebPPL always installs its own local version of WebPPL for stability: by default, it will install the most recent, compatible release. Advanced users may use the install_webppl() function to override this default to install from any official NPM release tag (e.g. '0.9.7') or any commit hash from the WebPPL github repository.

Primary features

For a complete introduction to RWebPPL's functionality, see this introduction.

Running models from R

Write a model as a string in R:

my_model <- '
   var model = function () {
      var a = flip(0.3)
      var b = flip(0.6)
      return a + b
   }
   model()
'
webppl(my_model)

Or write a model in an external file:

webppl(program_file = "path/to/model/model.wppl")

Passing data to WebPPL from R

Data can be passed directly from R to WebPPL as in:

my_model <- '
    var model = function(){
        var p = uniform(0, 1)
        map(function(d){
           observe(Binomial({n: d.n, p: p}), d.k)
        }, myDF)
    return p
    }
    Infer({model: model, method: "MCMC"})
'

webppl(my_model, data = df, data_var = "myDF")

In this example, myDF is not defined inside the WebPPL program, but is passed into it from R, using data = df. The argument data_var tells WebPPL what the data should be called. If unspecified, data_var will default to "data".

Running multiple chains (in parallel)

webppl(my_model, chains = 3, cores = 3)

Other options



mhtess/rwebppl documentation built on May 22, 2019, 8:57 p.m.