knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "README-"
)

Downloads from the RStudio CRAN mirror status

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "README-"
)

BoltzMM

The BoltzMM package allows for computation of probability mass functions of fully-visible Boltzmann machines (FVBMs) via pfvbm and allpfvbm. Random data can be generated using rfvbm. Maximum pseudolikelihood estimation of parameters via the MM algorithm can be conducted using fitfvbm. Computation of partial derivatives and Hessians can be performed via fvbmpartiald and fvbmHessian. Covariance estimation and normal standard errors can be computed using fvbmcov and fvbmstderr.

Installation

If devtools has already been installed, then the most current build of BoltzMM can be obtained via the command:

devtools::install_github('andrewthomasjones/BoltzMM',build_vignettes = TRUE)

The latest stable build of BoltzMM can be obtain from CRAN via the command:

install.packages("BoltzMM", repos='http://cran.us.r-project.org')

An archival build of BoltzMM is available at http://doi.org/10.5281/zenodo.2538256. Manual installation instructions can be found within the R installation and administration manual https://cran.r-project.org/doc/manuals/r-release/R-admin.html.

Examples

Compute the probability of every length n=3 binary spin vector under bvec and Mmat:

library(BoltzMM)
set.seed(1)

bvec <- c(0,0.5,0.25)
Mmat <- matrix(0.1,3,3) - diag(0.1,3,3)
allpfvbm(bvec,Mmat)

Generate num=1000 random strings of n=3 binary spin variables under bvec and Mmat.

library(BoltzMM)
set.seed(1)

num <- 1000
bvec <- c(0,0.5,0.25)
Mmat <- matrix(0.1,3,3) - diag(0.1,3,3)
data <- rfvbm(num,bvec,Mmat)

head(data)

Fit a fully visible Boltzmann machine to data, starting from parameters bvec and Mmat.

library(BoltzMM)
set.seed(1)

bvec <- c(0,0.5,0.25)
Mmat <- matrix(0.1,3,3) - diag(0.1,3,3)
data <- rfvbm(num,bvec,Mmat)

fitfvbm(data,bvec,Mmat)

Example with real data from https://hal.science/hal-01927188v1.

# Load bnstruct library & package
library(bnstruct)
library(BoltzMM)

# Load data
data(senate)

# Turn data into a matrix
senate_data <- as.matrix(senate)

# Recode Yes as 1, and No as -1
senate_data[senate=="Yes"] <- 1
senate_data[senate=="No"] <- -1

# Conduct imputation
imp_data <- knn.impute(suppressWarnings(matrix(as.numeric(senate_data),
                                        dim(senate_data))),
                       k=1)

# No governement - using as reference level
data_nogov <- imp_data[,-1]


# Initialize parameters
bvec <- rep(0,8)
Mmat <- matrix(0,8,8)
nullmodel<-list(bvec=bvec,Mmat=Mmat)

# Fit a fully visible Boltzmann machine to data, starting from parameters bvec and Mmat.
model <- fitfvbm(data_nogov,bvec,Mmat)
# Compute the sandwich covariance matrix using the data and the model.
covarmat <- fvbmcov(data_nogov,model,fvbmHess)
# Compute the standard errors of the parameter elements according to a normal approximation.
st_errors <- fvbmstderr(data_nogov,covarmat)
# Compute z-scores and p-values under null
test_results<-fvbmtests(data_nogov,model,nullmodel)

test_results

For more examples, see individual help files.

Technical references

Please refer to the following sources regarding various facets of the FVBM models that are implemented in the package.

The FVBM model and the consistency of their maximum pseudolikelihood estimators (MPLEs) was first considered in http://doi.org/10.1162/neco.2006.18.10.2283. The MM algorithm implemented in the main function fitfvbm was introduced in http://doi.org/10.1162/NECO_a_00813. Here various convergence results regarding the algorithm is proved. Next, the asymptotic normality results pertaining to the use of the functions fvbmstderr and fvbmtests are proved in http://doi.org/10.1109/TNNLS.2015.2425898. Finally, the senate data was introduced and analysed in https://hal.science/hal-01927188v1.

Reference to package

If you find this package useful in your work, then please follow the usual R instructions for citing the package in your publications. That is, follow the instructions from citation('BoltzMM').

# Citation instructions
citation('BoltzMM')

Authorship statement

The BoltzMM package is co-authored by Andrew T. Jones, Hien D. Nguyen, and Jessica J. Bagnall. The initial development of the package, in native R was conducted by HDN. Implementation of the core loops of the package in the C language was performed by ATJ. JJB formatted and contributed the senate data set as well as the example analysis on the senate data. All three co-authors contributed to the documentation of the software as well as troubleshooting and testing.

Unit testing

Using the package testthat, we have conducted the following unit test for the GitHub build, on the date: r format(Sys.time(), '%d %B, %Y'). The testing files are contained in the tests folder of the repository.

Bug reporting and contributions

Thank you for your interest in BoltzMM. If you happen to find any bugs in the program, then please report them on the Issues page (https://github.com/andrewthomasjones/BoltzMM/issues). Support can also be sought on this page. Furthermore, if you would like to make a contribution to the software, then please forward a pull request to the owner of the repository.



andrewthomasjones/BoltzMM documentation built on June 11, 2025, 8:12 p.m.