My question is very similar to this, but instead of accessing the iteration numbers, I want to access the previous draw and use it as data. Is that possible within Stan?
Put differently, in iteration t, I want to use the posterior draw from iteration t-1 as my data. Is that possible?
I know that one of the answers says that it is not possible within Stan because it is designed to be stateless. However, this answer does tell us how to access previous iteration numbers. I wonder if I could get some hint on how I can accomplish my goal.
Hi, and welcome! I don’t want to be presumptuous about why you want to do this and whether it’s a good idea, so…
You cannot do this within a Stan program using the features that are available and exposed through the Stan language. There’s probably a way to hack around in custom C++ to achieve this. An alternative route would be to chain together a bunch of calls to Stan that ask for one iteration of sampling each.
… but I can’t help but suggest (perhaps presumptuously) that this does not seem like a good idea, for at least two reasons. One is that the target density will change each iteration, which will make it difficult or impossible for warmup to effectively adapt to the target (also, finding a way to implement any warmup schedule at all will be nontrivial!). The other is that it seems like it would be quite difficult to achieve or even assess convergence in this context. I suspect that many of the heuristics that we use to assess convergence could prove fragile in unexpected ways if the data keep changing depending on the history of the exploration.
Would you mind elaborating on what you’re hoping to achieve by doing this?
You’re right that this is not a good idea. I figured out a way to solve my problem. Thank you.