MyNixOS website logo
Description

Bayesian Kernelized Tensor Regression.

Facilitates scalable spatiotemporally varying coefficient modelling with Bayesian kernelized tensor regression. The important features of this package are: (a) Enabling local temporal and spatial modeling of the relationship between the response variable and covariates. (b) Implementing the model described by Lei et al. (2023) <doi:10.48550/arXiv.2109.00046>. (c) Using a Bayesian Markov Chain Monte Carlo (MCMC) algorithm to sample from the posterior distribution of the model parameters. (d) Employing a tensor decomposition to reduce the number of estimated parameters. (e) Accelerating tensor operations and enabling graphics processing unit (GPU) acceleration with the 'torch' package.

BKTR

Intro

This project is a R implementation of the BKTR algorithm presented by Mengying Lei, Aurélie Labbe & Lijun Sun (2023). The article presenting the algorithm can be found here.

BKTR stands for Scalable Spatiotemporally Varying Coefficient Modelling with Bayesian Kernelized Tensor Regression. It allows to model spatiotemporally varying coefficients using a Bayesian framework. We implemented the algorithm and more in a R package that uses torch as a tensor operation backend.

For information, an alternative Python implementation of the algorithm can be found here. The Python implementation is synchronized with this repository and development is done in parallel. The synchronization of features will be done at a subrevision level (x.y.0).

An article presenting the R package in details is currently in preparation and should be available soon.

Installation

CRAN Installation

install.packages('BKTR')

Latest Development Version Installation

The latest development version on GitHub can be installed using the devtools package:

library(devtools)
devtools::install_github('julien-hec/BKTR', ref = 'main')

Notes

If you obtain an error message when installing the package, it may be due to the installation of the torch package. A common error message that can appear during BKTR installation is installation of package 'BKTR' had non-zero exit status. The torch package is a dependency of the BKTR package and there is a good chance that the error comes from the installation of torch. Because of its ability to perform tensor operations on the GPU, it can sometimes be more complicated to install than other R packages. We provide some guidance for the installation of torch below.

Installing torch alone

A simple way to see if BKTR installation problems come from the torch installation is to try to install torch alone first:

install.packages('torch')

If you obtain an error message, we encourage you to continue reading the following subsections.

Installing torch with a non-interactive R session

If you use a non-interactive R session (e.g. in a Docker container), you need to install LibTorch and LibLantern afterwards with the following command:

library(torch)
torch::torch_install()

Installation of torch for CPU only

If you have a CUDA version that causes issues during the torch installation and you just want to use the CPU version of BKTR, you can install torch with the CPU option:

Sys.setenv(CUDA='cpu')
install.packages('torch')

Installing torch with a specific CUDA version

If your CUDA version does not seem to be supported correctly and you obtain the following error message:

Error in `check_supported_version()`:
x Unsupported CUDA version "12.2"
i Currently supported versions are: "11.7" and "11.8".

As specified in the prebuilt section of torch's installation guide, you can try to install from specific precompiled binaries for another CUDA version:

options(timeout = 600) # increasing timeout since we download a 2GB file.
# For Windows and Linux: "cpu", "cu117", "cu118" are the only currently supported
# For MacOS the supported are: "cpu-intel" or "cpu-m1"
kind <- "cu118"
version <- available.packages()["torch","Version"]
options(repos = c(
  torch = sprintf("https://torch-cdn.mlverse.org/packages/%s/%s/", kind, version),
  CRAN = "https://cloud.r-project.org" # or any other from which you want to install the other R dependencies.
))
install.packages("torch")

More information on torch installation

For more information on how to install torch, please refer to the torch installation vignette.

Getting started with Colab

If you want to get started quickly with BKTR on Google Colab, you can use the following examples

Simple Example

To verify that everything is running smoothly you can try to run a BKTR regression on the BIXI data presented in the package. (The data is already preloaded in the package via the BixiDataR6 class). To use a subset of the BIXI dataset as a simple example, we can also use the is_light argument of the BixiData$new() method to only run our example on 25 stations and 50 days of data.

The following code will run a BKTR regression using sensible defaults on the simplified BIXI data and print a summary of the results.

library(BKTR)
bixi_data <- BixiData$new(is_light=TRUE)
bktr_regressor <- BKTRRegressor$new(
    data_df=bixi_data$data_df,
    spatial_positions_df=bixi_data$spatial_positions_df,
    temporal_positions_df=bixi_data$temporal_positions_df,
    burn_in_iter=200,
    sampling_iter=200
)
bktr_regressor$mcmc_sampling()
summary(bktr_regressor)

Contributing

Contributions are welcome. Do not hesitate to open an issue or a pull request if you encounter any problem or have any suggestion.

Metadata

Version

0.2.0

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows