Methods for extracting out MCMC behaviour from greta model
- Dominant language
- C++
- Stars
- 607
- Forks
- 67
- Avg merge
- 3d 8h
- Merged PRs (30d)
- 1
Description
relevant greta forum post: https://forum.greta-stats.org/t/how-to-get-info-of-mcmc-behaviour-from-the-result-of-mcmc/292
``` r
x <- iris$Petal.Length
y <- iris$Sepal.Length
library(greta)
#>
#> Attaching package: 'greta'
#> The following objects are masked from 'package:stats':
#>
#> binomial, cov2cor, poisson
#> The following objects are masked from 'package:base':
#>
#> %*%, apply, backsolve, beta, chol2inv, colMeans, colSums, diag,
#> eigen, forwardsolve, gamma, identity, rowMeans, rowSums, sweep,
#> tapply
int <- normal(0, 5)
#> ℹ Initialising python and checking dependencies, this may take a moment.
#> ✓ Initialising python and checking dependencies ... done!
#>
coef <- normal(0, 3)
sd <- lognormal(0, 3)
mean <- int + coef * x
distribution(y) <- normal(mean, sd)
m <- model(int, coef, sd)
draws <- mcmc(m)
#> running 4 chains simultaneously on up to 8 cores
#>
```
```
#> warmup 0/1000 \| eta: ?s warmup == 50/1000 \| eta: 35s warmup ==== 100/1000 \| eta: 23s warmup ====== 150/1000 \| eta: 18s warmup ======== 200/1000 \| eta: 16s warmup ========== 250/1000 \| eta: 14s warmup =========== 300/1000 \| eta: 12s warmup ============= 350/1000 \| eta: 11s warmup =============== 400/1000 \| eta: 10s warmup ================= 450/1000 \| eta: 9s warmup =================== 500/1000 \| eta: 8s warmup ===================== 550/1000 \| eta: 7s warmup ======================= 600/1000 \| eta: 6s warmup ========================= 650/1000 \| eta: 6s warmup =========================== 700/1000 \| eta: 5s warmup ============================ 750/1000 \| eta: 4s warmup ============================== 800/1000 \| eta: 3s warmup ================================ 850/1000 \| eta: 2s warmup ================================== 900/1000 \| eta: 2s warmup ==================================== 950/1000 \| eta: 1s warmup ====================================== 1000/1000 \| eta: 0s
#> sampling 0/1000 \| eta: ?s sampling == 50/1000 \| eta: 9s sampling ==== 100/1000 \| eta: 10s sampling ====== 150/1000 \| eta: 9s sampling ======== 200/1000 \| eta: 8s sampling ========== 250/1000 \| eta: 8s sampling =========== 300/1000 \| eta: 7s sampling ============= 350/1000 \| eta: 7s sampling =============== 400/1000 \| eta: 6s sampling ================= 450/1000 \| eta: 6s sampling =================== 500/1000 \| eta: 6s sampling ===================== 550/1000 \| eta: 5s sampling ======================= 600/1000 \| eta: 4s sampling ========================= 650/1000 \| eta: 4s sampling =========================== 700/1000 \| eta: 3s sampling ============================ 750/1000 \| eta: 3s sampling ============================== 800/1000 \| eta: 2s sampling ================================ 850/1000 \| eta: 2s sampling ================================== 900/1000 \| eta: 1s sampling ==================================== 950/1000 \| eta: 1s sampling ====================================== 1000/1000 \| eta: 0s
attr(draws, “model_info”)*s**a**m**p**l**e**r**s*\[\[1\]\]numerical_rejections
#> \[1\] 0
greta_info \<- function(x){
attr(x, “model_info”)
}
greta_samplers \<- function(x){
greta_info(x)$samplers
}
draw_info \<- greta_info(draws)
draw_info$samplers
#> $`1`
#> Error in vapply(x, format, ““, big.mark = big.mark, big.interval = big.interval, : values must be length 1,
#> but FUN(X\[\[4\]\]) result is length 3
numerical_rejections \<- function(x){
purrr::map(greta_samplers(x), \~purrr::pluck(.x, “numerical_rejections”))
}
numerical_rejections(draws)
#> $`1`
#> \[1\] 0
```
Created on 2021-09-20 by the [reprex package](https://reprex.tidyverse.org) (v2.0.1)
Session info
```r
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 4.1.0 (2021-05-18)
#> os macOS Big Sur 10.16
#> system x86_64, darwin17.0
#> ui X11
#> language (EN)
#> collate en_AU.UTF-8
#> ctype en_AU.UTF-8
#> tz Australia/Perth
#> date 2021-09-20
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date lib source
#> abind 1.4-5 2016-07-21 [1] CRAN (R 4.1.0)
#> backports 1.2.1 2020-12-09 [1] CRAN (R 4.1.0)
#> base64enc 0.1-3 2015-07-28 [1] CRAN (R 4.1.0)
#> callr 3.7.0 2021-04-20 [1] CRAN (R 4.1.0)
#> cli 3.0.1 2021-07-17 [1] CRAN (R 4.1.0)
#> coda 0.19-4 2020-09-30 [1] CRAN (R 4.1.0)
#> codetools 0.2-18 2020-11-04 [1] CRAN (R 4.1.0)
#> crayon 1.4.1 2021-02-08 [1] CRAN (R 4.1.0)
#> digest 0.6.27 2020-10-24 [1] CRAN (R 4.1.0)
#> ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.1.0)
#> evaluate 0.14 2019-05-28 [1] CRAN (R 4.1.0)
#> fansi 0.5.0 2021-05-25 [1] CRAN (R 4.1.0)
#> fs 1.5.0 2020-07-31 [1] CRAN (R 4.1.0)
#> future 1.21.0 2020-12-10 [1] CRAN (R 4.1.0)
#> globals 0.14.0 2020-11-22 [1] CRAN (R 4.1.0)
#> glue 1.4.2 2020-08-27 [1] CRAN (R 4.1.0)
#> greta * 0.3.1.9012 2021-08-06 [1] local
#> highr 0.9 2021-04-16 [1] CRAN (R 4.1.0)
#> hms 1.1.0 2021-05-17 [1] CRAN (R 4.1.0)
#> htmltools 0.5.1.1 2021-01-22 [1] CRAN (R 4.1.0)
#> jsonlite 1.7.2 2020-12-09 [1] CRAN (R 4.1.0)
#> knitr 1.33 2021-04-24 [1] CRAN (R 4.1.0)
#> lattice 0.20-44 2021-05-02 [1] CRAN (R 4.1.0)
#> lifecycle 1.0.0 2021-02-15 [1] CRAN (R 4.1.0)
#> listenv 0.8.0 2019-12-05 [1] CRAN (R 4.1.0)
#> magrittr 2.0.1 2020-11-17 [1] CRAN (R 4.1.0)
#> Matrix 1.3-4 2021-06-01 [1] CRAN (R 4.1.0)
#> parallelly 1.26.1 2021-06-30 [1] CRAN (R 4.1.0)
#> pillar 1.6.2 2021-07-29 [1] CRAN (R 4.1.0)
#> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.1.0)
#> png 0.1-7 2013-12-03 [1] CRAN (R 4.1.0)
#> prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.1.0)
#> processx 3.5.2 2021-04-30 [1] CRAN (R 4.1.0)
#> progress 1.2.2 2019-05-16 [1] CRAN (R 4.1.0)
#> ps 1.6.0 2021-02-28 [1] CRAN (R 4.1.0)
#> purrr 0.3.4 2020-04-17 [1] CRAN (R 4.1.0)
#> R6 2.5.1 2021-08-19 [1] CRAN (R 4.1.0)
#> Rcpp 1.0.7 2021-07-07 [1] CRAN (R 4.1.0)
#> reprex 2.0.1 2021-08-05 [1] CRAN (R 4.1.0)
#> reticulate 1.20 2021-05-03 [1] CRAN (R 4.1.0)
#> rlang 0.4.11 2021-04-30 [1] CRAN (R 4.1.0)
#> rmarkdown 2.9 2021-06-15 [1] CRAN (R 4.1.0)
#> rstudioapi 0.13 2020-11-12 [1] CRAN (R 4.1.0)
#> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 4.1.0)
#> stringi 1.7.3 2021-07-16 [1] CRAN (R 4.1.0)
#> stringr 1.4.0 2019-02-10 [1] CRAN (R 4.1.0)
#> styler 1.4.1 2021-03-30 [1] CRAN (R 4.1.0)
#> tensorflow 2.5.0 2021-06-10 [1] CRAN (R 4.1.0)
#> tfruns 1.5.0 2021-02-26 [1] CRAN (R 4.1.0)
#> tibble 3.1.3 2021-07-23 [1] CRAN (R 4.1.0)
#> utf8 1.2.2 2021-07-24 [1] CRAN (R 4.1.0)
#> vctrs 0.3.8 2021-04-29 [1] CRAN (R 4.1.0)
#> whisker 0.4 2019-08-28 [1] CRAN (R 4.1.0)
#> withr 2.4.2 2021-04-18 [1] CRAN (R 4.1.0)
#> xfun 0.24 2021-06-15 [1] CRAN (R 4.1.0)
#> yaml 2.2.1 2020-02-01 [1] CRAN (R 4.1.0)
#>
#> [1] /Library/Frameworks/R.framework/Versions/4.1/Resources/library
Contributor guide
Assessment
This issue has not been assessed yet.