I’ve written my own MCMC code. MCMCChains provides some helper functions wrt working with already completed chains.
As I iterate through the chain, what is the best way to store the each pass? E.g., if I complete non-burn pass 1757/10,000, and state contains vectors and scalars, say state is (;a=3.0, b=[4.0,6.0,7.0]), should I just push the draws to a DataFrame, or is there a better purpose-built solution?
function recordstate(;i,state,records)
#put state into records
end
records = #some data type
recordstate(;i=1757, state=(;a=3.0, b=[4.0,6.0,7.0]),records)
Might just be a case where a standardized solution is more trouble than it is worth. To be fair, it is not like an intermediate structure is a huge burden to code up.
After some additional experimentation, it does seem possible to keep a handle to the underlying arrays in the chain e.g. a=rand(10); c=Chains(a,:a); creates the chain without copying. Then indexing directly into the three dimensional arrays seems to work (e.g. c[2,:a,1]=1.0) .
A bit cumbersome but serviceable if needed. However, seems like the interface intends the user to convert at the end so I might just do that, especially since I’m not sure how the copying/referencing will work in future releases.
In fact it might well be less code burden than trying to fill in an array… But it is a lot of memory, particularly if you’re doing something like sampling 10k samples in 4 chains of a model with 10k parameters.
Yeah- I ended up creating a wrapper object around the chain instead of an intermediate object. The wrapper contains views for accessing the chains for each of my parameters. Then I overloaded getproperty so I can use the “.” syntax for further ease of access- best of all I can still use the MCMCChain analytics without needing to create a new object.