Flow adaptation fits much worse when the posterior scale is small

Open
#367 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
python

Research direction

Start by running the included 50-dimensional normal example and compare fisher_distance and final step size at the two covariance scales. The payload does not name implementation files or tests, and says the cause is unknown, so trace how adaptation="flow" and with_transform_adapt handle scale changes. Done means the flow fits comparably at small and unit scales while sampling still recovers the target statistics.

Written by the indexing model from the issue text.

Description

bug normalizing-flows

adaptation="flow" fits the flow much worse when the posterior's scale is small, even with x64 enabled. On a correlated 50-dimensional normal, the mean fisher distance is 0.025 at unit scale and 2090 after scaling the covariance by 1e-8, and the final step size drops from 1.62 to 0.066. Sampling still recovers the means and standard deviations to within about 15%, and the cause isn't established.

import jax

jax.config.update("jax_enable_x64", True)

import numpy as np
import pymc as pm

import nutpie

rng = np.random.default_rng(0)
dim = 50
factor = rng.normal(size=(dim, dim)) / np.sqrt(dim)
correlation = factor @ factor.T + 0.1 * np.eye(dim)

for scale in [1.0, 1e-4]:
    with pm.Model() as model:
        pm.MvNormal("x", mu=np.zeros(dim), cov=correlation * scale**2)

    compiled = nutpie.compile_pymc_model(model, backend="jax", gradient_backend="jax")
    trace = nutpie.sample(compiled.with_transform_adapt(num_layers=4), adaptation="flow",
                          chains=1, draws=500, seed=1, progress_bar=False)
    print(f"scale={scale:.0e}  fisher_distance={float(trace.sample_stats['fisher_distance'].mean()):.3f}")
# scale=1e+00  fisher_distance=0.025
# scale=1e-04  fisher_distance=2090.241
Dominant language
Python
Stars
214
Forks
31
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from pymc-devs/nutpie

All issues in pymc-devs/nutpie

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.