Wiki

Clone wiki

OpenBT / Home

OpenBT-small.jpg

Welcome to the OpenBT (Open Bayesian Trees) project

OpenBT is a flexible and extensible C++ framework for implementing Bayesian regression tree models. Currently a number of models and inference tools are available for use in the released code with additional models/tools under development. The code makes use of MPI for parallel computing. The software is a stand-alone program that can be accessed from a variety of front-end interfaces; currently an R interface is provided via the Ropenbt package to demonstrate use of the software.

Binary OpenBT packages are available for Ubuntu and Mac OS/X. On the Windows platform, the software works under the Windows 10 WSL layer. Versions of Windows earlier than Windows 10 are not supported.

The easiest way to try out the software is:

  1. Download a current binary build from the links below.

  2. Fire up your R session and follow the R examples below.


Binary Downloads

Recent Ubuntu and OS/X builds are available as binary packages. For alternate Linux distributions, consider a package conversion utility such as alien.

Ubuntu

  1. Download the OpenBT Ubuntu Linux 20.04 package: Ubuntu 20.04 binary MPI package

  2. Install the Ubuntu package from the command line using

    $ cd /location/of/downloaded/.deb
    $ sudo apt-get install ./openbt_0.current_amd64-MPI_Ubuntu_20.04.deb
    

Mac OS/X

  1. Install the OS/X OpenMPI package by running the following brew commands in a terminal window:

    $ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
    $ brew install open-mpi
    

  2. Download the OpenBT OSX binary package: Mac OS/X binary MPI package

  3. Install the OpenBT OSX package by double-clicking on the downloaded .pkg file and follow the on-screen instructions.

Windows 10 WSL Instructions

OpenBT will run within the Windows 10 Windows Subsystem for Linux (WSL) environment. For instructions on installing WSL, please see Ubuntu on WSL. We recommend installing the Ubuntu 20.04 WSL build. There are also instructions here on keeping your Ubuntu WSL up to date, or installing additional features like X support.

Once you have installed the WSL Ubuntu layer, start the WSL Ubuntu shell from the start menu and then install the package:

$ cd /mnt/c/location/of/downloaded/.deb
$ sudo apt install openbt_0.current_amd64-MPI_Ubuntu_20.04.deb

Currently, you will also need to install R within the WSL shell environment and work from there:

$ sudo apt-get install r-base
However, we hope to add the capability to access the WSL OpenBT install from the Windows desktop R environment at some point.


Example

To use OpenBT in R, there is a front-end R interface, Ropenbt, that can be installed directly from bitbucket using the remotes package (you could alternatively use devtools if you prefer). First, make sure remotes is installed:

#!R
install.packages("remotes")

Now install Ropenbt directly from bitbucket:

#!R
remotes::install_bitbucket("mpratola/openbt/Ropenbt")

Note that some Ropenbt package dependencies may also be installed.

Next, let's create a test function. A popular one is the Branin function:

#!R
# Test Branin function, rescaled
braninsc <- function(xx)
{  
  x1 <- xx[1]
  x2 <- xx[2]

  x1bar <- 15*x1 - 5
  x2bar <- 15 * x2

  term1 <- x2bar - 5.1*x1bar^2/(4*pi^2) + 5*x1bar/pi - 6
  term2 <- (10 - 10/(8*pi)) * cos(x1bar)

  y <- (term1^2 + term2 - 44.81) / 51.95
  return(y)
}


# Simulate branin data for testing
set.seed(99)
n=500
p=2
x = matrix(runif(n*p),ncol=p)
y=rep(0,n)
for(i in 1:n) y[i] = braninsc(x[i,])

And then we can load the Ropenbt package and fit a BART model. Here we set the model type as model="bart" which ensures we fit a homoscedastic BART model. The number of MPI threads to use is specified as tc=4. For a list of all optional parameters, see args(openbt).

#!R
library(Ropenbt)
fit=openbt(x,y,tc=4,model="bart",modelname="branin")

Next we can construct predictions and make a simple plot. Here, we are calculating the in-sample predictions since we passed the same x matrix to the predict.openbt() function.

#!R
# Calculate in-sample predictions
fitp=predict.openbt(fit,x,tc=4)

# Make a simple plot
plot(y,fitp$mmean,xlab="observed",ylab="fitted")
abline(0,1)

To save the model, use the openbt.save() function. Similarly, load the model using openbt.load(). Because the posterior can be large in sample-based models such as these, the fitted model is saved in a compressed file format with the extension .obt.

#!R
# Save fitted model as test.obt in the working directory
openbt.save(fit,"test")

# Load fitted model to a new object.
fit2=openbt.load("test")

The standard variable activity information, calculated as the proportion of splitting rules involving each variable, can be computed using the openbt.vartivity() function.

#!R
# Calculate variable activity information
fitv=vartivity.openbt(fit2)

# Plot variable activity
plot(fitv)

A more accurate alternative is to calculate the Sobol' indices.

#!R
# Calculate Sobol indices
fits=sobol.openbt(fit2)
fits$msi
fits$mtsi
fits$msij

For more examples of using OpenBT, explore the example.R file in the repo.

Updated