mcsamplerNFlow: return (p_s, p_prior, rv), and give it a sampling_density - #358
Draft
oshaughnessy-junior wants to merge 1 commit into
Draft
oshaughnessy-junior wants to merge 1 commit into
oshaughnessy-junior wants to merge 1 commit into
Conversation
…sity draw_simplified returned (rv, p_s, p_prior) while MCSamplerGeneric and every other implementation return (p_s, p_prior, rv). mcsamplerPortfolio.draw() unpacks the latter, so an NFlow member had the samples assigned to joint_p_s. --sampler-portfolio NFlow is offered by both util_ConstructIntrinsicPosterior_GenericCoordinates and util_ConstructEOSPosterior, so the broken configuration is reachable. The failure is not reliably loud. On an [AV, NFlow] portfolio over a unit Gaussian in [-5,5]^d, d=2 raises a broadcast ValueError out of the portfolio, but d=1 completes and returns ln Z = -4.458 against a true -1.384 -- 3.07 nats low, silently, because the (1,n) sample array broadcasts into the (n,) density slot. Control with the NFlow member replaced by a second AV: -1.273. Also adds sampling_density(X), which mcsamplerPortfolio needs to build its balance-heuristic mixture denominator q_mix = sum_m frac_m q_m, and coerces n_to_get to a python int (nflows type-checks it with isinstance(n, int), which a numpy int fails, and the portfolio hands members a numpy int64). Verified against a real nflows install; the new gate needs neither nflows nor torch. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
oshaughnessy-junior
deployed
to
private-review-dispatch-rift
September 16, 2026 14:29 — with
GitHub Actions
Active
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
mcsamplerNFlowcould not be amcsamplerPortfoliomember. Two causes, both fixed.Return order.
draw_simplifiedreturned(rv, p_s, p_prior).MCSamplerGenericand every other implementation return(p_s, p_prior, rv).mcsamplerPortfolio.draw()unpacks that order, so an NFlow member had its samples assigned tojoint_p_s.--sampler-portfolio NFlowis offered byutil_ConstructIntrinsicPosterior_GenericCoordinatesandutil_ConstructEOSPosterior.The failure is not always loud. An [AV, NFlow] portfolio on a unit Gaussian in [-5,5]^d:
ValueError: could not broadcast input array from shape (2,100) into shape (100,)At d=1 the (1,n) sample array broadcasts into the (n,) density slot, and the run returns a number 3.07 nats low with no error.
Missing
sampling_density. The portfolio buildsq_mix = sum_m frac_m q_mfrommember.sampling_density(X). Added, modelled on themcsamplerEnsembleandmcsamplerAdaptiveVolumeversions:1/Von the box whilenf_flow is None,exp(flow.log_prob(X))once a flow is trained. On a trained 2-D flow it matches thep_sreported for the same draws to 1.2e-7.Reaching either needed one more fix:
nflowstype-checks its sample count withisinstance(n, int), which the numpy int64 the portfolio passes fails.Verification
nflowsandtorchare absent from the CIT IGWN conda python. Real-dependency runs used~/.conda/envs/myigwn-py310-testing(python 3.10.14, torch 2.1.2, numpy 1.24.4) onldas-grid, no cupy.test_NF_reuse.py --as-test(OPTDEP, real nflows).travis/test-ci-roster.pyThe new gate needs neither package: it drives the untrained uniform branch and a strict in-file flow stand-in, and stubs both at import when absent. Registered in
.travis/test-integrate.shwith a collection-count guard.Two things this does not fix
Both follow from one root:
draw_simplifiedtruncates to the box without renormalizing.mcsamplerPortfolio.drawcopies into a fixed-width slice, so a real NFlow member still dies:could not broadcast input array from shape (45,) into shape (114,).portfolio.draw()passes no kwargs, soenforce_bounds=Falseis unreachable from there.p_sis the undividedq(x)while accepted draws are distributed asq(x)/A. With the short-chunk problem patched out in the harness, the [AV, NFlow] portfolio runs and lands +0.093 nats high over 5 seeds, against +0.012 for an AV+AV control.Fixing these changes how
draw_simplifiedsamples, which also moves NFlow's ownintegrate(). Your call, so I left them.The brief for this work said PR #356 (
claude/portfolio-ps-contract) was merged. It is open.🤖 Generated with Claude Code