Giter Club home page Giter Club logo

sgmcmc's Introduction

sgmcmc: a stochastic gradient MCMC package for R

Travis-CI Build Status CRAN_Status_Badge

sgmcmc implements popular stochastic gradient Markov chain Monte Carlo (SGMCMC) methods including stochastic gradient Langevin dynamics (SGLD), stochastic gradient Hamiltonian Monte Carlo (SGHMC) and stochastic gradient Nosé-Hoover thermostat (SGNHT). The package uses automatic differentiation, so all the differentiation needed for the methods is calculated automatically. Control variate methods can be used in order to improve the efficiency of the methods as proposed in the recent publication.

The package is built on top of the TensorFlow library for R, which has a lot of support for statistical distributions and operations, which allows a large class of posteriors to be built. More details can be found at the TensorFlow R library webpage, also see the TensorFlow API for full documentation.

Citing sgmcmc

To cite the sgmcmc package, please reference the accompanying paper. Sample Bibtex is given below:

@article{sgmcmc-package,
  title={sgmcmc: An R package for stochastic gradient Markov chain Monte Carlo},
  author={Baker, Jack and Fearnhead, Paul and Fox, Emily B and Nemeth, Christopher},
  journal={Journal of Statistical Software},
  volume={91},
  number={3},
  pages={1--27},
  year={2019}
}

Installation

sgmcmc requires TensorFlow for R to be installed, which requires packages that can't be automatically built by R, so has a few steps:

  • Install the sgmcmc R package: install.packages("sgmcmc").
  • Install the required python packages (including TensorFlow and TensorFlow Probability) by running: sgmcmc::installTF().

If you already have the TensorFlow and TensorFlow probability packages installed, then this should be autodetected by the package and you can skip the final step. Make sure these are up to date though, as the TensorFlow API is under active development and still changes quite regularly. Especially ensure that your TensorFlow and TensorFlow probability modules are compatible.

Documentation

It's recommended you start here. This getting started page outlines the general structure of the package and its usage.

There's also worked examples for the following models (these will be extended as the package matures):

The SGMCMC algorithms can also be run step by step, which allows custom storage of parameters using test functions, or sequential estimates. Useful if your chain is too large to fit into memory! This requires a better knowledge of TensorFlow. An example of this is given in the neural network vignette.

Finally full details of the API can be found here.

For the source code, and bug reporting, see the Github page.

Issues Running Examples

If you are having issues running the examples, as a first port of call please make sure your TensorFlow installation is the most up to date version. A lot of issues are simply because the TensorFlow API has changed. If you're still having issues, please file a bug report.

sgmcmc's People

Contributors

chris-nemeth avatar jackcbaker avatar

Stargazers

 avatar Yuanhe Zhang avatar  avatar Satie avatar Sreekumar Thaithara Balan avatar Theodore Papamarkou avatar Siva avatar Li-Li avatar Tim Roberts avatar Justin M. Shea avatar Shreyash Patodia avatar Russell Dinnage avatar Leah South avatar Xiangyun Huang avatar Ianpapa avatar Tl Yim avatar Jiacheng Zhu avatar Jeff Hammerbacher avatar  avatar Slava Nikitin avatar David Torres avatar  avatar  avatar Jamie Fairbrother avatar Stas Sajin avatar  avatar Richard Guo avatar Junpeng Lao avatar

Watchers

James Cloos avatar  avatar  avatar  avatar Christos avatar Srshti avatar paper2code - bot avatar

sgmcmc's Issues

SGHMC does not work for simulated logistic regression

I was trying to run SGHMC on a logistic regression model with 100,000 x 50 simulated data but the algorithm would not converge unless I set the stepsize to very small i.e. 5e-10. Then the posteriors would just be way off from the true posteriors (true betas are randomly chosen between -1 and 1). Would you please give me some insights on this? Thank you very much!

Error: No TensorFlow Probability python installation found. This can be installed using the installTF() function.

Hello,

It keeps sending this error but I can't figure out what to correct,

I am using Anaconda and launching my jupyter notebook from an R and python environment that I created where I have the packages of tensorflow probability 0.8.0 , and r-sgmcmc 0.2.4.

with this, I had a warning to ensure that tensorflow is of a compatible version

so in my anaconda's packages, I disabled tensorflow and tensorflow-base 2.0.0 and left r-tensorflow 1.13.1 and tensorflow probability 0.8.0 , I no longer had the warning after loading the library :
library(sgmcmc)

but I then when I run the code :

sgld = sgldSetup(logLik, dataset, params, stepsize, logPrior = logPrior, 
        minibatchSize = 500, seed = 13)

I got the message :

Error: No TensorFlow Probability python installation found. This can be installed using the installTF() function.
Traceback:

  1. sgldSetup(logLik, dataset, params, stepsize, logPrior = logPrior,
    . minibatchSize = 500, seed = 13)
  2. createSGMCMC(logLik, logPrior, dataset, params, stepsize, minibatchSize,
    . seed)
  3. checkTFInstall()
  4. stop(tfpErrorMsg(), call. = FALSE)

I run sgmcmc::installTF() and tensorflow::install_tensorflow()

I still get the same error,
I also have tried installing the packages from CRAN repository url in RStudio (launched from the same environment) , I get this same error,

Thank you!

Potential incompatibility with TF2

I try to run examples from help and get.:

Error in py_get_attr_impl(x, name, silent) : 
  AttributeError: module 'tensorflow' has no attribute 'placeholder'

I have found this thread suggesting TF2 has no placeholder attribute.

My session:

> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] sgmcmc_0.2.5     tensorflow_2.2.0

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.5       lattice_0.20-41  fansi_0.4.1      crayon_1.3.4     assertthat_0.2.1 rappdirs_0.3.1   grid_4.0.2       jsonlite_1.7.1   magrittr_1.5    
[10] tfruns_1.4       cli_2.0.2        rstudioapi_0.11  whisker_0.4      Matrix_1.2-18    reticulate_1.16  tools_4.0.2      glue_1.4.2       compiler_4.0.2  
[19] base64enc_0.1-3 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.