See this as an example https://mc-stan.org/loo/articles/loo2-moment-matching.html#moment-matching-correction-for-importance-sampling.
In R, loo(fit, moment_match = TRUE) just works because fit is a stanfit object, so it can internally call things like rstan::log_prob() and rstan::constrain_pars() to re-evaluate the posterior and log-likelihoods at new parameter values during moment matching. The user doesn't need to provide anything extra in most cases.
Since we're backend-agnostic we can't auto-derive those functions, so we'll need the user to provide unconstrained draws, a log_prob_upars_fn, and a log_lik_i_upars_fn. We already have the full loo_moment_match() implementation that takes all of these (it mirrors R's generic loo_moment_match.default() path). The work is really just wiring it into loo() so users can pass moment_match=True along with the required functions and any kwargs and we handle the workflow internally.
See this as an example https://mc-stan.org/loo/articles/loo2-moment-matching.html#moment-matching-correction-for-importance-sampling.
In R,
loo(fit, moment_match = TRUE)just works because fit is astanfitobject, so it can internally call things likerstan::log_prob()andrstan::constrain_pars()to re-evaluate the posterior and log-likelihoods at new parameter values during moment matching. The user doesn't need to provide anything extra in most cases.Since we're backend-agnostic we can't auto-derive those functions, so we'll need the user to provide unconstrained draws, a
log_prob_upars_fn, and alog_lik_i_upars_fn. We already have the fullloo_moment_match()implementation that takes all of these (it mirrors R's genericloo_moment_match.default()path). The work is really just wiring it intoloo()so users can passmoment_match=Truealong with the required functions and anykwargsand we handle the workflow internally.