Accessing samples in MCMCChains

I’ve got Turing to sample my model… sort-of. It’s stuck and I’m trying to figure out what the samples look like.

The model is a fit of a time-series. So there are parameters that are vectors like Ac which is a 3 vector and represents some periodic noise.

It’s clear from the Readme that I can do

get(chain,:Ac) and I’ll get back a 3-tuple of vectors.

Suppose I want to sample ONE iteration, say the 200th and I want to get Ac as a vector… how do I do it?

[get(chain,:Ac).Ac[i][200] for i in 1:3]

is there something easier?

I haven’t tried it, but maybe use broadcasting like

getindex.(chain.Ac, 200)

So in my example, Ac is the name of a vector parameter… there’s Ac[1],Ac[2],Ac[3] (there’s an even longer parameter Arbf which has 20 odd dimensions).

these are separate variables in the chain. When I do get(chain,:Ac) I get:

julia> get(chain,:Ac)
(Ac = ([0.32228709765451763 -0.3877980743116929; 0.3163860790999562 -0.38479165892268785; … ; 0.31895958580486605 -0.3156285003214462; 0.30888825934550446 -0.3198781895652254], [2.322569930200603 2.872963818099482; 2.314061819602352 2.8748381553809788; … ; 2.347355232722247 2.800025888639181; 2.340723325565215 2.7959559127543203], [-0.2897274052240421 0.36649297086057114; -0.2863375221649774 0.36842656904584226; … ; -0.25923055662025973 0.19406550561162855; -0.26198777592822214 0.20150952347443402]),)

So if you want to unparse that, this is a named tuple with one entry, Ac, the value is an unnamed tuple of three vectors…

if I do:

getindex.(get(chain,:Ac).Ac,200) I wind up with a 3 tuple:

julia> getindex.(get(chain,:Ac).Ac,200)
(0.3032212499585117, 2.338802084753996, -0.25473893714523604)

I guess that might work fine for my purposes. Suppose I have a really high dimensional parameter though, like 1500, is there an advantage to having an Array rather than a high dimensional tuple?

in the end I want to call my predictor function with the values of the parameters:


where Ac and As and Arb are vectors because inside my predictor there’s linear algebra going on (dot products and rescalings and things).

Ultimately, it seems like inside a Chain is an array, and it would be great if I could just slice out the piece of the array that I am interested in, and look at that… so

chain.value[200,13:25,1] for example… except how do I figure out which are the dimensions associated with the stuff I want to slice out?