https://github.com/bisaloo/mcmcensemble
R Package Providing Ensemble Sampler for Affine-Invariant MCMC
Science Score: 13.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
○codemeta.json file
-
○.zenodo.json file
-
✓DOI references
Found 8 DOI reference(s) in README -
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (13.3%) to scientific vocabulary
Keywords
mcmc
mcmc-sampler
r-package
Last synced: 6 months ago
·
JSON representation
Repository
R Package Providing Ensemble Sampler for Affine-Invariant MCMC
Basic Info
- Host: GitHub
- Owner: Bisaloo
- License: gpl-2.0
- Language: R
- Default Branch: main
- Homepage: http://hugogruson.fr/mcmcensemble/
- Size: 38.4 MB
Statistics
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 2
- Releases: 6
Fork of SandaD/MCMCEnsembleSampler
Topics
mcmc
mcmc-sampler
r-package
Created over 5 years ago
· Last pushed 7 months ago
https://github.com/Bisaloo/mcmcensemble/blob/main/
# mcmcensemble
[](https://CRAN.R-project.org/package=mcmcensemble)
[](https://github.com/Bisaloo/mcmcensemble/actions)
[](https://app.codecov.io/gh/Bisaloo/mcmcensemble?branch=main)
[](https://lifecycle.r-lib.org/articles/stages.html)
This R package provides ensemble samplers for affine-invariant Monte
Carlo Markov Chain, which allow a faster convergence for badly scaled
estimation problems. Two samplers are proposed: the
differential.evolution sampler from ter Braak and Vrugt
([2008](#ref-terBraak2008)) and the stretch sampler from Goodman and
Weare ([2010](#ref-Goodman2010)).
For theoretical background about Ensemble MCMC (what are the benefits
over simple MCMC? How do they work? What are the pitfalls?), please
refer for example to [this lecture](https://doi.org/10.26207/46za-m573)
from Eric B. Ford (Penn State).
## Installation
You can install the stable version of this package from
[CRAN](https://cran.r-project.org/package=mcmcensemble):
``` r
install.packages("mcmcensemble")
```
or the development version from [GitHub](https://github.com/bisaloo),
via my [r-universe](https://bisaloo.r-universe.dev/packages):
``` r
install.packages("mcmcensemble", repos = "https://bisaloo.r-universe.dev")
```
## Usage
``` r
library(mcmcensemble)
## a log-pdf to sample from
p.log <- function(x) {
B <- 0.03 # controls 'bananacity'
-x[1]^2 / 200 - 1/2 * (x[2] + B * x[1]^2 - 100 * B)^2
}
## set options and starting point
n_walkers <- 10
unif_inits <- data.frame(
"a" = runif(n_walkers, 0, 1),
"b" = runif(n_walkers, 0, 1)
)
## use stretch move
res1 <- MCMCEnsemble(p.log, inits = unif_inits,
max.iter = 5000, n.walkers = n_walkers,
method = "stretch")
#> Using stretch move with 10 walkers.
attr(res1, "ensemble.sampler")
#> [1] "stretch"
str(res1)
#> List of 2
#> $ samples: num [1:10, 1:500, 1:2] 0.42619 0.45413 0.00133 0.59391 0.35217 ...
#> ..- attr(*, "dimnames")=List of 3
#> .. ..$ : chr [1:10] "walker_1" "walker_2" "walker_3" "walker_4" ...
#> .. ..$ : chr [1:500] "generation_1" "generation_2" "generation_3" "generation_4" ...
#> .. ..$ : chr [1:2] "a" "b"
#> $ log.p : num [1:10, 1:500] -2.8 -3.91 -2.68 -2.93 -2.25 ...
#> ..- attr(*, "dimnames")=List of 2
#> .. ..$ : chr [1:10] "walker_1" "walker_2" "walker_3" "walker_4" ...
#> .. ..$ : chr [1:500] "generation_1" "generation_2" "generation_3" "generation_4" ...
#> - attr(*, "ensemble.sampler")= chr "stretch"
```
If the [coda](https://cran.r-project.org/package=coda) package is
installed, you can then use the `coda = TRUE` argument to get objects of
class `mcmc.list`. The coda package then allows you to call `summary()`
and `plot()` to get informative and nicely formatted results and plots:
``` r
## use stretch move, return samples as 'coda' object
res2 <- MCMCEnsemble(p.log, inits = unif_inits,
max.iter = 5000, n.walkers = n_walkers,
method = "stretch", coda = TRUE)
#> Using stretch move with 10 walkers.
attr(res2, "ensemble.sampler")
#> [1] "stretch"
summary(res2$samples)
#>
#> Iterations = 1:500
#> Thinning interval = 1
#> Number of chains = 10
#> Sample size per chain = 500
#>
#> 1. Empirical mean and standard deviation for each variable,
#> plus standard error of the mean:
#>
#> Mean SD Naive SE Time-series SE
#> a -1.5494 8.498 0.12018 1.1111
#> b 0.7705 3.266 0.04619 0.4006
#>
#> 2. Quantiles for each variable:
#>
#> 2.5% 25% 50% 75% 97.5%
#> a -20.109 -6.9976 -0.7515 4.372 13.670
#> b -9.008 -0.1602 1.7794 2.867 4.279
plot(res2$samples)
```
``` r
## use different evolution move, return samples as 'coda' object
res3 <- MCMCEnsemble(p.log, inits = unif_inits,
max.iter = 5000, n.walkers = n_walkers,
method = "differential.evolution", coda = TRUE)
#> Using differential.evolution move with 10 walkers.
attr(res3, "ensemble.sampler")
#> [1] "differential.evolution"
summary(res3$samples)
#>
#> Iterations = 1:500
#> Thinning interval = 1
#> Number of chains = 10
#> Sample size per chain = 500
#>
#> 1. Empirical mean and standard deviation for each variable,
#> plus standard error of the mean:
#>
#> Mean SD Naive SE Time-series SE
#> a -0.5135 7.958 0.11255 0.5623
#> b 1.1336 2.535 0.03585 0.1869
#>
#> 2. Quantiles for each variable:
#>
#> 2.5% 25% 50% 75% 97.5%
#> a -16.322 -5.964466 -0.2292 5.587 13.379
#> b -5.544 0.002173 1.7944 2.819 4.353
plot(res3$samples)
```
To see more plotting and MCMC diagnostic options, please refer to the
relevant vignette:
[`vignette("diagnostic-pkgs", package = "mcmcensemble")`](https://hugogruson.fr/mcmcensemble/articles/diagnostic-pkgs.html)
## Progress bar
You can choose to enable a progress bar thanks to the
[progressr](https://cran.r-project.org/package=progressr) package. This
can be done by adding the following line to your script before running
`MCMCEnsemble()`:
``` r
progressr::handlers(global = TRUE) # requires R >= 4.0
progressr::handlers("progress")
MCMCEnsemble(p.log, inits = unif_inits,
max.iter = 5000, n.walkers = n_walkers,
method = "differential.evolution", coda = TRUE)
```
## Parallel processing
This package is set up to allow transparent parallel processing when
requested by the user thanks to the framework provided by the
[future](https://cran.r-project.org/package=future) package. To enable
parallel processing, you must run:
``` r
future::plan("multiprocess")
```
at the start of your session.
## Similar projects
The Goodman-Weare stretch sampler is also available in the [tonic R
package](https://github.com/SimonVaughanDataAndCode/tonic).
The methods used in this package also have (independent) implementations
in other languages:
- [emcee v3: A Python ensemble sampling toolkit for affine-invariant
MCMC](https://doi.org/10.21105/joss.01864)
- [GWMCMC which implements the Goodman-Weare stretch sampler in
Matlab](https://github.com/grinsted/gwmcmc)
## Who is talking about this package?
- [R View from October
2020](https://rviews.rstudio.com/2020/11/19/october-2020-top-40-new-cran-packages/)
## References
Goodman, Jonathan, and Jonathan Weare. 2010. Ensemble Samplers with
Affine Invariance. *Communications in Applied Mathematics and
Computational Science* 5 (1): 6580.
.
ter Braak, Cajo J. F., and Jasper A. Vrugt. 2008. Differential
Evolution Markov Chain with Snooker Updater andFewer Chains.
*Statistics and Computing* 18 (4): 43546.
.
Owner
- Name: Hugo Gruson
- Login: Bisaloo
- Kind: user
- Location: Heidelberg
- Company: EMBL
- Website: https://hugogruson.fr/
- Repositories: 102
- Profile: https://github.com/Bisaloo
Evolutionary Biologist turned Research Software Engineer in R.
GitHub Events
Total
- Create event: 1
- Release event: 1
- Issues event: 4
- Delete event: 1
- Member event: 1
- Issue comment event: 7
- Push event: 13
- Pull request review comment event: 1
- Pull request event: 3
- Pull request review event: 3
- Fork event: 1
Last Year
- Create event: 1
- Release event: 1
- Issues event: 4
- Delete event: 1
- Member event: 1
- Issue comment event: 7
- Push event: 13
- Pull request review comment event: 1
- Pull request event: 3
- Pull request review event: 3
- Fork event: 1
Committers
Last synced: almost 3 years ago
All Time
- Total Commits: 182
- Total Committers: 5
- Avg Commits per committer: 36.4
- Development Distribution Score (DDS): 0.11
Top Committers
| Name | Commits | |
|---|---|---|
| Hugo Gruson | h****n@p****m | 162 |
| Sanda Dejanic | s****c@e****h | 10 |
| Andreas Scheidegger | a****r@e****h | 4 |
| Sanda | a****a@g****m | 3 |
| Hugo Gruson | B****o@u****m | 3 |
Committer Domains (Top 20 + Academic)
eawag.ch: 2
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 6
- Total pull requests: 2
- Average time to close issues: 2 days
- Average time to close pull requests: 11 days
- Total issue authors: 2
- Total pull request authors: 1
- Average comments per issue: 0.83
- Average comments per pull request: 0.0
- Merged pull requests: 2
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 1
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 1
- Pull request authors: 0
- Average comments per issue: 0.0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- Bisaloo (6)
- scheidan (1)
Pull Request Authors
- scheidan (2)
- Bisaloo (2)
Top Labels
Issue Labels
help wanted (3)
question (2)
enhancement (1)
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- cran 356 last-month
- Total docker downloads: 41,971
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 6
- Total maintainers: 1
cran.r-project.org: mcmcensemble
Ensemble Sampler for Affine-Invariant MCMC
- Homepage: https://hugogruson.fr/mcmcensemble/
- Documentation: http://cran.r-project.org/web/packages/mcmcensemble/mcmcensemble.pdf
- License: GPL-2
-
Latest release: 3.2.0
published 7 months ago
Rankings
Forks count: 28.8%
Dependent packages count: 29.8%
Stargazers count: 31.7%
Dependent repos count: 35.5%
Average: 36.5%
Downloads: 57.0%
Maintainers (1)
Last synced:
6 months ago