Skip to content

Commit

Permalink
merged in master branch
Browse files Browse the repository at this point in the history
  • Loading branch information
danielturek committed Jun 14, 2024
2 parents 8ca5c0a + ccd70d7 commit 61c6c90
Show file tree
Hide file tree
Showing 8 changed files with 364 additions and 78 deletions.
38 changes: 29 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,36 @@

[![tests](https://github.com/nimble-dev/nimbleHMC/workflows/tests/badge.svg)](https://github.com/nimble-dev/nimbleHMC/actions)

Provides derivative-based MCMC sampling algorithms for use in conjunction with the `nimble` package. These include:
Provides derivative-based MCMC sampling algorithms and convenence functions, for use in conjunction with the MCMC engine avaialble in the `nimble` package. Sampling algorithms include:

- Hamiltonian Monte Carlo (HMC-NUTS) sampler
- No-U-Turn Hamiltonian Monte Carlo (`NUTS`) sampler
- Historical implementation of the original No-U-Turn HMC (`NUTS_classic`) sampler
- Langevin sampler (*under development*)

See the [nimble website](https://r-nimble.org/) for more information and examples.
See the HMC section of the [nimble user manual](https://r-nimble.org/html_manual/cha-mcmc.html#subsec:HMC) for more information and examples.

[General package information](https://cran.r-project.org/web/packages/nimbleHMC/) about `nimbleHMC`, and the [complete API for package functions](https://cran.r-project.org/web/packages/nimbleHMC/nimbleHMC.pdf) are available on CRAN.

Additional information about the `nimble`package itself is available at the [nimble website](https://r-nimble.org/).

<!--
The nimbleHMC package must be used with nimble version XXXX or
higher. To check the current version number of nimble use `packageVersion("nimble")`.
-->

### Package Requirements

`nimbleHMC` must be used with version `1.0.0` or higher of the `nimble` package.
### Installation and Package Requirements

Use of `nimbleHMC` requires installation of the core `nimble` package. Detailed instructions for installing `nimble` are available in the [`nimble` package README](https://github.com/nimble-dev/nimble/blob/devel/README.md).

`nimbleHMC` must be used with version `1.0.0` or higher of `nimble`, or the latest version available on CRAN. To check the version number of the currently installed version of `nimble`, use:

```r
packageVersion("nimble")
```

The `nimbleHMC` package itself can be installed directly from CRAN, using:

```r
install.packages("nimbleHMC")
```


<!--
library(remotes)
Expand Down Expand Up @@ -61,6 +76,11 @@ dmy_distribution <- nimbleFunction(
```


### Contributing and Support

Contributions to the `nimbleHMC` package should be submitted via pull request on GitHub. For additional guideliens on making contributions, please see the [contributing guidelines for the `nimble` package](https://github.com/nimble-dev/nimble/blob/devel/CONTRIBUTING.md).

Issues, feature requests, or bugs should be reported using GitHub issues, submitted to the `nimbleHMC` repository.

For additional support using `nimble` or `nimbleHMC`, please see the [nimble user manual](https://r-nimble.org/html_manual/cha-welcome-nimble.html). Any additional questions can be submitted to the [nimble-users Google group](https://groups.google.com/g/nimble-users).

6 changes: 4 additions & 2 deletions make_package.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ library(devtools)

setwd('~/github/nimble/nimbleHMC')

document('nimbleHMC')
devtools::document('nimbleHMC')

system('R CMD BUILD nimbleHMC')
devtools::build('nimbleHMC')

check('nimbleHMC')

Expand All @@ -23,6 +23,8 @@ suppressMessages(try(remove.packages('nimbleHMC'), silent = TRUE))
message('installing package version ', gsub('\\.tar\\.gz$', '', lastTarFile))
system(paste0('R CMD install ', lastTarFile))

##devtools::install('nimbleHMC')

q('no')

1
Expand Down
6 changes: 3 additions & 3 deletions nimbleHMC/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: nimbleHMC
Title: Hamiltonian Monte Carlo and Other Gradient-Based MCMC Sampling Algorithms for 'nimble'
Version: 0.2.0
Date: 2023-09-11
Version: 0.2.2
Date: 2024-02-08
Authors@R: c(person("Daniel", "Turek", role = c("aut", "cre"), email = "[email protected]"),
person("Perry", "de Valpine", role = "aut"),
person("Christopher", "Paciorek", role = "aut"))
Expand All @@ -14,4 +14,4 @@ License: BSD_3_clause + file LICENSE | GPL (>= 2)
Copyright: See COPYRIGHTS file.
Encoding: UTF-8
LazyData: false
RoxygenNote: 7.3.0
RoxygenNote: 7.3.1
13 changes: 8 additions & 5 deletions nimbleHMC/R/HMC_configuration.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#' Add a No-U-Turn (NUTS) Hamiltonian Monte Carlo (HMC) sampler to an existing nimble MCMC configuration object
#'
#' @param conf A nimble MCMC configuration object, as returned by `configureMCMC`.
#' @param target A character vector of continuous-valued stochastic node names to sample. If this argument contains any discrete-valued nodes, an error is produced and no sampler is added.
#' @param target A character vector of continuous-valued stochastic node names to sample. If this argument contains any discrete-valued nodes, an error is produced and no HMC sampler is added. If this argument is omitted, then no HMC sampler is added.
#' @param type A character string specifying the type of HMC sampler to add, either "NUTS" or "NUTS_classic". See `help(NUTS)` or `help(NUTS_classic)` for details of each sampler. The default sampler type is "NUTS".
#' @param control Optional named list of control parameters to be passed as the `control` argument to the HMC sampler. See `help(NUTS)` or `help(NUTS_classic)` for details of the control list elements accepted by each sampler.
#' @param replace Logical argument. If `TRUE`, any existing samplers operating on the specified nodes will be removed, prior to adding the HMC sampler. Default value is `FALSE`.
Expand Down Expand Up @@ -46,11 +46,14 @@
#'
#' Rmodel <- nimbleModel(code, constants, data, inits, buildDerivs = TRUE)
#'
#' ## create MCMC configuration object
#' conf <- configureMCMC(Rmodel, nodes = NULL)
#' ## create default MCMC configuration object
#' conf <- configureMCMC(Rmodel)
#'
#' ## add HMC sampler operating on all stochastic model nodes
#' addHMC(conf)
#' ## remove default samplers operating on b0 and b1
#' conf$removeSamplers(c("b0", "b1"))
#'
#' ## add an HMC sampler operating on b0 and b1
#' addHMC(conf, target = c("b0", "b1"))
#'
#' Rmcmc <- buildMCMC(conf)
#'
Expand Down
Loading

0 comments on commit 61c6c90

Please sign in to comment.