Skip to content

SBBRMI: no embedded Laplace (Stan laplace_marginal) for @plate cell latents, blocked upstream on stan-dev/math#3438 #3

Open

Description

@nsiccha

Summary

BRM has no spelling that integrates a @plate cell latent out with Stan's embedded Laplace approximation (laplace_marginal, Stan 2.37 or later), so cell latents are always sampled. An opt-in SBBRMI lowering was investigated and is on hold: on a synthetic model it does not run with the Stan that BRM compiles against, and it could not be sampled even with the pending upstream fix.

Model

Synthetic: 18 cells with 8 to 16 Gaussian latents each, log_T ~ Normal(location, scale), where location and scale depend on 56 population parameters. The latents are observed through T = exp(log_T): by noisy counts on about 70 % of the entries, and by the cell total with a 0.2 % relative standard deviation.

Findings

With BridgeStan 2.9.0 (Stan 2.39, Stan Math 5.3.0):

  • laplace_marginal returns NaN for 17 of the 18 cells at the true parameter values, with solvers 1, 2 and 3 and tolerances from 1e-3 to 1e-8.
  • The cause is upstream. The likelihood is not log-concave (its negative Hessian is indefinite even at the mode in 12 of 18 cells). Solvers 1 and 2 need a positive-definite matrix and fail from the default start, so Stan falls through to solver 3. Solver 3 reaches the mode, but its compute_log_determinant takes log of the signed LU diagonal. That is NaN whenever partial pivoting leaves a negative pivot, although det(B) > 0 in every cell.
  • Fix: Return the final Newton iterate as the Laplace latent mean, and fix the solver-3 log determinant stan-dev/math#3438 (open).
  • Started at the exact conditional mode, all three solvers return the correct Laplace value.

With #3438 applied to a local copy of Stan Math:

  • Values are finite, but one gradient costs about 440 times the joint model's.
  • The marginal is not smooth at small scales: directional finite differences agree with the gradient at step 1e-2 and diverge below 1e-4.
  • NUTS (4 chains) did not finish warm-up in 30 minutes. The joint model sampled 4 × 1,000 draws in about a minute.

Resume condition

Revisit when a BridgeStan release ships a Stan Math with #3438, and its marginal is smooth on this shape. Re-measure on this model before adding a lowering. Any such lowering must be opt-in. A per-unit Laplace for the RK backend (RKBRMI) is being developed separately.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions