Extract the inverse metric (mass matrix) for each MCMC chain.

inv_metric(matrix = TRUE)

Arguments

matrix

(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.

Value

A list of length equal to the number of MCMC chains. See the matrix

argument for details.

See also

Examples

# \dontrun{
fit <- cmdstanr_example("logistic")
fit$inv_metric()
#> $`1`
#>          [,1]      [,2]      [,3]      [,4]
#> [1,] 0.041261 0.0000000 0.0000000 0.0000000
#> [2,] 0.000000 0.0524298 0.0000000 0.0000000
#> [3,] 0.000000 0.0000000 0.0481435 0.0000000
#> [4,] 0.000000 0.0000000 0.0000000 0.0732764
#> 
#> $`2`
#>           [,1]      [,2]     [,3]      [,4]
#> [1,] 0.0476774 0.0000000 0.000000 0.0000000
#> [2,] 0.0000000 0.0504326 0.000000 0.0000000
#> [3,] 0.0000000 0.0000000 0.052821 0.0000000
#> [4,] 0.0000000 0.0000000 0.000000 0.0711489
#> 
#> $`3`
#>           [,1]     [,2]      [,3]      [,4]
#> [1,] 0.0465449 0.000000 0.0000000 0.0000000
#> [2,] 0.0000000 0.058276 0.0000000 0.0000000
#> [3,] 0.0000000 0.000000 0.0462442 0.0000000
#> [4,] 0.0000000 0.000000 0.0000000 0.0746648
#> 
#> $`4`
#>          [,1]      [,2]     [,3]      [,4]
#> [1,] 0.043908 0.0000000 0.000000 0.0000000
#> [2,] 0.000000 0.0657091 0.000000 0.0000000
#> [3,] 0.000000 0.0000000 0.048942 0.0000000
#> [4,] 0.000000 0.0000000 0.000000 0.0632482
#> 
fit$inv_metric(matrix=FALSE)
#> $`1`
#> [1] 0.0412610 0.0524298 0.0481435 0.0732764
#> 
#> $`2`
#> [1] 0.0476774 0.0504326 0.0528210 0.0711489
#> 
#> $`3`
#> [1] 0.0465449 0.0582760 0.0462442 0.0746648
#> 
#> $`4`
#> [1] 0.0439080 0.0657091 0.0489420 0.0632482
#> 

fit <- cmdstanr_example("logistic", metric = "dense_e")
fit$inv_metric()
#> $`1`
#>             [,1]        [,2]        [,3]        [,4]
#> [1,]  0.05192450 -0.00808928  0.00233609  0.00537011
#> [2,] -0.00808928  0.05617200 -0.00192090 -0.00711062
#> [3,]  0.00233609 -0.00192090  0.04964080 -0.01391690
#> [4,]  0.00537011 -0.00711062 -0.01391690  0.07126540
#> 
#> $`2`
#>             [,1]         [,2]        [,3]        [,4]
#> [1,] 0.044604400  0.000608339  0.00107581  0.00451756
#> [2,] 0.000608339  0.058117400 -0.01088670 -0.00141863
#> [3,] 0.001075810 -0.010886700  0.04437890 -0.00650639
#> [4,] 0.004517560 -0.001418630 -0.00650639  0.06984850
#> 
#> $`3`
#>             [,1]         [,2]         [,3]        [,4]
#> [1,]  0.04180740 -0.001275980  0.005750270  0.00305686
#> [2,] -0.00127598  0.054490900 -0.000483551 -0.00770396
#> [3,]  0.00575027 -0.000483551  0.044247700 -0.01478120
#> [4,]  0.00305686 -0.007703960 -0.014781200  0.06501070
#> 
#> $`4`
#>              [,1]         [,2]         [,3]        [,4]
#> [1,]  4.17467e-02 -0.000269914  4.51726e-05  0.00472656
#> [2,] -2.69914e-04  0.061160800 -1.36053e-02 -0.00637189
#> [3,]  4.51726e-05 -0.013605300  4.96363e-02 -0.00759941
#> [4,]  4.72656e-03 -0.006371890 -7.59941e-03  0.06762740
#> 
# }