devtools::install_github("quentingronau/bridgesampling@stan_interface")[...]
> - A method that recompiles the C++ code of a model from the fitted stanfit object. Currently we cannot call and rstan::log_prob() or rstan::unconstrain_pars() if the model was fitted in a different R session. Given that the stanfit object contains everything needed for compiling (minus the original data object), that seems in principle solvable.
I've been lobbying for exactly the opposite approach. If you have
your model code somewhere (ideally in a standalone file), you don't
need to reconsistitute a fit object.
But I'm not a heavy or native R user, so take this with a grain of
salt. I think they're going to keep the
god-object approach that's so common in R (e.g., return object for glm()):
https://en.wikipedia.org/wiki/God_object
> - Ability to pass more than one set of samples per call to rstan::unconstrain_pars().
> But we are obviously happy to wait until rstan3 as we found workarounds for both problems (in the first case the user needs to compile the model again just without samples and pass both).
This is just a simple mapper function (something that applies a function to
a sequence)? You provide a sequence of parameter values and get a sequence of
unconstrained values?
- Bob
> On Apr 18, 2017, at 3:21 AM, Henrik Singmann <sing...@gmail.com> wrote:
>
> H Bob,
>
> To respond to your points.
>
> Am Montag, 17. April 2017 20:29:36 UTC+2 schrieb Bob Carpenter:
> [...]
> > - A method that recompiles the C++ code of a model from the fitted stanfit object. Currently we cannot call and rstan::log_prob() or rstan::unconstrain_pars() if the model was fitted in a different R session. Given that the stanfit object contains everything needed for compiling (minus the original data object), that seems in principle solvable.
>
> I've been lobbying for exactly the opposite approach. If you have
> your model code somewhere (ideally in a standalone file), you don't
> need to reconsistitute a fit object.
>
> But I'm not a heavy or native R user, so take this with a grain of
> salt. I think they're going to keep the
> god-object approach that's so common in R (e.g., return object for glm()):
>
> https://en.wikipedia.org/wiki/God_object
>
> I can see that for stanfit objects, which can be of considerable size, it might make sense to restrict them to the necessary bare bones (such as just the posterior samples and not also part of the model). But I also believe that for us it does not really matter in the end. We just need a reliable method to call log_prob() whether the samples were obtained in the current R session or a previous one.
I think that's fine if you're on the same hardware platform.
When you change hardware, R versions, C++ libs, etc., you run
into incompatibilities.
The bit you need is the compiled model, which is specifically what
you're having trouble reconstituting. No way to get the log densities,
gradients, or transforms out without it (and with data loaded).
Thanks for your reply Bob.
I’m pretty sure you can get the fitted ADVI parameters out of RStan and CmdStan.
I couldn’t see any reference for this in the documentation for RStan / CmdStan - is this something that hasn’t been documented yet? The closest I can see in the get_posterior_mean method of the stanfit object returned by the RStan vb function, however from the description it seems this may be estimated from samples or just not be applicable to a vb stanfit output.
How are you evaluating the stability of ADVI? We’re having massive problems with convergence across multiple model types. So any tips would be appreciated.
We get an indication of how well ADVI fits the posterior from the marginal density on the inverse temperature parameter when sampling in the extended space. If the ADVI converges to a good fit and so the KL from the base density (ADVI fit) to target density is low, then the marginal density on the inverse temperature should be relatively flat (in particular the log ratio of the densities at inverse temperatures one and zero will be equal in expectation to the KL divergence from the ADVI base to target density). If the inverse temperature samples are all close to one, this suggests there is a large remaining KL between the variational approximation and target, though this can also be due to poor convergence of the MCMC chain in the extended space so its only partially useful as a diagnostic. Also even if the ADVI has converged, as it could be the optima converged to still has a large KL from the target if the family used for the variational approximation is a poor fit to the true target, this is more a diagnosis of the goodness of the variational fit than stability / convergence. In our PyMC3 experiments, we also used a long annealed importance sampling run as a proxy ground truth to evaluate both the ADVI fit and the estimate of the marginal likelihood from our method.