Skip to content

Add moment_match argument to loo() #328

@jordandeklerk

Description

@jordandeklerk

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions