Pathfinder.jl icon indicating copy to clipboard operation
Pathfinder.jl copied to clipboard

FR: Add flag to retry if the log density and/or log density gradient can't be evaluated for (enough) draws from the approximate distribution returned by Pathfinder.

Open nsiccha opened this issue 5 months ago • 1 comments

As in the title. I feel like I should keep my titles shorter and instead put things in the description.

IMO, if the log density (gradient) fails to be evaluated for enough draws from the returned distribution, this is indicative of Pathfinder having failed. Even if it did not "fail", requiring that the log density gradient can be evaluated for the returned draws would be helpful e.g. for NUTS initialization purposes.

nsiccha avatar Jul 24 '25 09:07 nsiccha

Yeah, so currently we already evaluate the target log-density for:

  • All draws that are recycled from the ELBO calculation
  • All draws returned by multipathfinder with importance=True

But we don't evaluate the gradient for any of these. It's true that while most draws/models with a finite log-density will have a finite gradient, that's not guaranteed, and it does make sense for us to have an option to either draw-until-gradient-is-finite or filter-draws-to-those-with-finite-gradient. This should be optional and disabled by default, since for some models with expensive gradients the cost of this check could be significant.

Practically, the only reason Pathfinder returns draws at all is to avoid redundant computation in multi-path Pathfinder when importance sampling (draws from the multi-normal approximation are cheap, but computing the importance weights could be costly). I've long been dissatisfied that the user doesn't have all possible options for drawing samples available to them after Pathfinder terminates (e.g. drawing new samples and importance reweighting), so perhaps this is a good time to also think about a more flexible interface for getting new draws that would support not only this specific feature but also others.

sethaxen avatar Jul 24 '25 09:07 sethaxen