Let’s assume we have a target density, \pi(\theta), defined in a Stan file. Let’s assue that \theta is in 1000 dimensions. We are developing an algorithm that uses a projection, \theta=\theta_0+\phi\delta where \phi might be in 5 dimensions (where \delta would then be in 5x1000 dimensions).

To integrate this algorithm with Stan, we want to compile the Stan file once such that, at each stage in the algorithm, we can then evaluate \pi(\theta_0+\phi\delta) and \frac{d\pi(\theta_0+\phi\delta)}{d\phi} for a given \theta_0, \delta and \phi without calculating any derivatives in 1000 dimensions (which we assume would be computationally wasteful).

Our proposed solution is to automate the generation of a second Stan file that defines \theta_0 and \delta as 'Data’, defines \phi as 'Parameters’, compiles once and then uses the copy constructor to reinitialise the resulting object (such that we can 'change’ \theta_0 and \delta without recompiling).

We hope that makes sense and are interested in comments on this approach.