A Base R, simple implementation of the No-Underrun Sampler. This package aims to mostly directly implement the algorithm as described by th
1---
2output: github_document
3---
4
5<!-- README.md is generated from README.Rmd. Please edit that file -->
6
7```{r, include = FALSE}
8knitr::opts_chunk$set(
9 collapse = TRUE,
10 comment = "#>",
11 fig.path = "man/figures/README-",
12 out.width = "100%"
13)
14```
15
16# R.NURS
17
18<!-- badges: start -->
19<!-- badges: end -->
20
21A Base R, simple implementation of the No-Underrun Sampler. This implementation aims to mostly directly implement the algorithm as described by the paper, with at most small changes for code aesthetics and performance. This version uses the memory saving technique described in section 2.2.
22
23This code doesn't parallelize the density calculation for orbit extensions but doing so is trivial.
24
25## Installation
26
27You can install the development version of R.NURS from [GitHub](https://github.com/) with:
28
29``` r
30# install.packages("pak")
31pak::pak("VisruthSK/R.NURS")
32```
33
34## Example: Neal's Funnel
35
36```{r funnel}
37library(R.NURS)
38library(ggplot2)
39
40set.seed(0)
41logpdf_funnel <- function(theta) {
42 y <- theta[1]
43 dnorm(y, 0, 3, log = TRUE) + sum(dnorm(theta[-1], 0, exp(y / 2), log = TRUE))
44}
45
46samples <- NURS(
47 logpdf_funnel,
48 theta_init = rep(0, 15),
49 n = 5000,
50 epsilon = 0.1,
51 h = 0.5,
52 M = 5
53)
54
55data.frame(y = samples[, 1], x1 = samples[, 2]) |>
56 ggplot(aes(x = y, y = x1)) +
57 geom_point(alpha = 0.3) +
58 theme_minimal()
59```
60
61## References
62
63* Nawaf Bou-Rabee, Bob Carpenter, Sifan Liu, Stefan Oberdörster. 2025.
64[The No-Underrun Sampler: A locally adaptive, gradient free, MCMC
65method](https://arxiv.org/abs/2501.18548v2). *arXiv* 2501.18548 v2.
66
67* Art B. Owen. 2013. [Monte Carlo theory, methods and examples](https://artowen.su.domains/mc/). *artowen.su.domains*.