Pathfinder

Pathfinder.jl fits a Gaussian approximation to the posterior in unconstrained coordinates. It provides approximate posterior draws and can help initialise MCMC. Load Pathfinder to enable its Wren model methods:

using Wrenusing Wren.Dists: Gamma, Poissonusing Random: Xoshirousing Pathfinder@wren function poisson_rate(count)    rate ~ Gamma(2.0, 1.0)    @observe count ~ Poisson(rate)endmodel = poisson_rate(3)fit = multipathfinder(model, 100; rng=Xoshiro(42))

Pathfinder.multipathfinder accepts a model, a draw count and a keyword RNG. It returns Pathfinder's native result and approximation diagnostics. draws_transformed is a model-space FlexiChains.VNChain, ready for plotting, summaries and prediction:

chain = fit.draws_transformedmean(chain[@vn(rate)])
2.492769619365953

fit.draws contains unconstrained parameter vectors, one per column. Both fit.fit_distribution and fit.fit_distribution_transformed remain in unconstrained coordinates. The density includes the change-of-variables Jacobian, as for NUTS, rather than the original-space MAP objective.

Single and multiple paths

Pathfinder.pathfinder fits one Gaussian approximation and returns a native PathfinderResult. Its draw count is a keyword:

single = pathfinder(model; rng=Xoshiro(43), ndraws=100)single.draws_transformed
╭─FlexiChain (100 iterations, 1 chain) ────────────────────────────────────────╮
│ ↓ iter  = 1:100                                                              │
│ → chain = 1:1                                                                │
│                                                                              │
│ Parameters (1) ── VarName                                                    │
│  Float64  rate                                                               │
│                                                                              │
│ Extras (4)                                                                   │
│  Int64    return_value                                                       │
│  Float64  logprior, loglikelihood, logjoint                                  │
╰──────────────────────────────────────────────────────────────────────────────╯

For multipathfinder, four Gaussian fits form the mixture used for Pareto-smoothed importance resampling by default. Set nruns to change the number of fits:

fit = multipathfinder(model, 100; rng=Xoshiro(44), nruns=8)fit.psis_result.pareto_shape
0.6268528384625074

The fits are mixture components, not independent MCMC chains. All draws share one chain index, regardless of nruns. Check the ELBO estimates in fit.pathfinder_results and the Pareto shape diagnostic when assessing the approximation. Each path also has model-space draws in draws_transformed. These are approximate draws, not converged MCMC samples.

Options

Both methods accept adtype, as for nuts, and forward Pathfinder options such as history_length and solver tolerances.

init sets the optimiser's starting point in model space, as a latent source such as FromValues(VarNamedTuple(rate=2.0)). By default, it is drawn from init_sampler (see below). For multipathfinder, init is a collection of latent sources whose length determines the number of fits instead of nruns. If an optimisation run fails, Pathfinder retries from a new starting point drawn from init_sampler, which is also a latent source. As in Pathfinder, it defaults to drawing each unconstrained coordinate uniformly from [-s, s], where s is set by init_scale (default 2); this is the same as init_sampler=FromUnconstrainedInterval(-s, s). To start from the prior instead, pass init_sampler=FromPrior().

Both methods require ntasks=1; multipathfinder also requires ntasks_per_run=1. Wren's model arguments and AD preparation may hold mutable state, so both methods run sequentially. It copies the model arguments before preparing the density.