Extract the inverse metric (mass matrix) for each MCMC chain.
inv_metric(matrix = TRUE)
(logical) If a diagonal metric was used, setting matrix = FALSE
returns a list containing just the diagonals of the matrices instead
of the full matrices. Setting matrix = FALSE
has no effect for dense
metrics.
A list of length equal to the number of MCMC chains. See the matrix
argument for details.
# \dontrun{
fit <- cmdstanr_example("logistic")
fit$inv_metric()
#> $`1`
#> [,1] [,2] [,3] [,4]
#> [1,] 0.0431002 0.0000000 0.0000000 0.0000000
#> [2,] 0.0000000 0.0583438 0.0000000 0.0000000
#> [3,] 0.0000000 0.0000000 0.0531465 0.0000000
#> [4,] 0.0000000 0.0000000 0.0000000 0.0786797
#>
#> $`2`
#> [,1] [,2] [,3] [,4]
#> [1,] 0.0454991 0.0000000 0.0000000 0.0000000
#> [2,] 0.0000000 0.0809962 0.0000000 0.0000000
#> [3,] 0.0000000 0.0000000 0.0496686 0.0000000
#> [4,] 0.0000000 0.0000000 0.0000000 0.0688616
#>
#> $`3`
#> [,1] [,2] [,3] [,4]
#> [1,] 0.0406769 0.000000 0.0000000 0.0000000
#> [2,] 0.0000000 0.054686 0.0000000 0.0000000
#> [3,] 0.0000000 0.000000 0.0544764 0.0000000
#> [4,] 0.0000000 0.000000 0.0000000 0.0675343
#>
#> $`4`
#> [,1] [,2] [,3] [,4]
#> [1,] 0.0434081 0.0000000 0.0000000 0.0000000
#> [2,] 0.0000000 0.0669723 0.0000000 0.0000000
#> [3,] 0.0000000 0.0000000 0.0466104 0.0000000
#> [4,] 0.0000000 0.0000000 0.0000000 0.0654703
#>
fit$inv_metric(matrix=FALSE)
#> $`1`
#> [1] 0.0431002 0.0583438 0.0531465 0.0786797
#>
#> $`2`
#> [1] 0.0454991 0.0809962 0.0496686 0.0688616
#>
#> $`3`
#> [1] 0.0406769 0.0546860 0.0544764 0.0675343
#>
#> $`4`
#> [1] 0.0434081 0.0669723 0.0466104 0.0654703
#>
fit <- cmdstanr_example("logistic", metric = "dense_e")
fit$inv_metric()
#> $`1`
#> [,1] [,2] [,3] [,4]
#> [1,] 4.31917e-02 0.00404353 0.00504066 9.28594e-06
#> [2,] 4.04353e-03 0.05741780 -0.00262368 -9.31332e-03
#> [3,] 5.04066e-03 -0.00262368 0.04816930 -1.40772e-02
#> [4,] 9.28594e-06 -0.00931332 -0.01407720 7.29028e-02
#>
#> $`2`
#> [,1] [,2] [,3] [,4]
#> [1,] 0.05586860 -0.00758105 0.00327655 0.00186063
#> [2,] -0.00758105 0.06515060 -0.00821290 -0.00560473
#> [3,] 0.00327655 -0.00821290 0.05351870 -0.01152510
#> [4,] 0.00186063 -0.00560473 -0.01152510 0.06850340
#>
#> $`3`
#> [,1] [,2] [,3] [,4]
#> [1,] 0.05023130 0.00119935 0.00439778 -0.00486186
#> [2,] 0.00119935 0.06410140 -0.00267351 -0.01118110
#> [3,] 0.00439778 -0.00267351 0.04945990 -0.01316990
#> [4,] -0.00486186 -0.01118110 -0.01316990 0.07295030
#>
#> $`4`
#> [,1] [,2] [,3] [,4]
#> [1,] 0.05218850 -0.00108995 0.00814572 0.00609612
#> [2,] -0.00108995 0.06646310 -0.00283644 -0.01047740
#> [3,] 0.00814572 -0.00283644 0.05347060 -0.01085170
#> [4,] 0.00609612 -0.01047740 -0.01085170 0.07278000
#>
# }