Skip to content

portfolio: fix --save-samples 0-row export (cumsum linear weights + -inf guard) - #35

Closed
oshaughnessy-junior wants to merge 1 commit into
rift_O4dfrom
claude/jovial-lichterman-222363
Closed

portfolio: fix --save-samples 0-row export (cumsum linear weights + -inf guard)#35
oshaughnessy-junior wants to merge 1 commit into
rift_O4dfrom
claude/jovial-lichterman-222363

Conversation

@oshaughnessy-junior

Copy link
Copy Markdown
Owner

Problem

mcsamplerPortfolio.py --save-samples exported 0 sample rows for peaked (low-to-moderate n_eff) portfolio runs — even at n_eff≈9.

Step 2 of the _rvs cleanup paired the sorted index with the log-weight ln_wt[k] and cumsummed that, so the "cumulative weight" was never a cumulative probability. Any -inf ln_wt entry (rejected/underflowed sample) poisoned the cumsum (cum_sum[-1] = -infnan on normalize), and the cum_sum > deltaP mask kept 0 rows. The block was inherited from the original ccd70ff7 draft (copied from the ensemble pattern) but dropped the linear-weight step.

Fix

  • Pair/cumsum the linear weight wt[k] (already computed one line earlier), matching the canonical mcsampler/mcsamplerEnsemble truncation.
  • Map any non-finite log-weight to -inf (→ zero linear weight), with a degenerate fallback that keeps all rows if no finite-weight sample survives.
  • Confined to the portfolio Step 2 block — AV/GMM standalone samplers are untouched.

Verified numerically: reproduces canonical linear-weight index selection exactly on finite peaked input, and keeps all real samples (dropping only zero-weight rejects) when -inf entries are present (old code kept 0).

Also (docs only, no XML schema change)

The sparse sim_inspiral XML from --save-samples carries lnL only and cannot be reweighted by likelihood for a weighted-posterior/shape check. Added a code comment + updated --save-samples help text pointing users to the ASCII --extrinsic-proposal-output (full log-weight) / --calibration-export-posterior.

Validation note

The shape-recovery merge gate (S250114ax best-fit point, --save-samples --save-P 0) needs GPU + data and was not run in the authoring environment — please run it before merge.

🤖 Generated with Claude Code

…inf guard)

Step 2 of the _rvs cleanup in mcsamplerPortfolio.py paired the sorted index
with the LOG-weight ln_wt[k] and cumsummed that, so the "cumulative weight"
was never a cumulative probability. Any -inf ln_wt entry (rejected/underflowed
sample) poisoned the cumsum (cum_sum[-1] = -inf -> nan on normalize), and the
cum_sum > deltaP mask kept 0 rows -- 0 samples exported even at n_eff~9.

Fix: pair/cumsum the LINEAR weight wt[k] (already computed one line earlier),
matching the canonical mcsampler/mcsamplerEnsemble truncation, and map any
non-finite log-weight to -inf (-> zero linear weight) with a degenerate
fallback that keeps all rows if no finite-weight sample survives. Verified to
reproduce canonical linear-weight index selection exactly on finite peaked
input and to keep all real samples (dropping only zero-weight rejects) when
-inf entries are present. Change is confined to the portfolio Step 2 block;
AV/GMM standalone samplers are untouched.

Also document (integrate_likelihood_extrinsic_batchmode) that the sparse
sim_inspiral XML from --save-samples carries lnL only and must not be
reweighted by likelihood for a weighted-posterior/shape check; point users to
the ASCII --extrinsic-proposal-output (full log-weight) / --calibration-export-posterior.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
oshaughnessy-junior added a commit that referenced this pull request Jul 26, 2026
…tory; add ensemble+pooling harness

Correcting my own 3-seed 'cap8 is reliably modest' claim (survivorship bias): 10 cap8
draws span 1->70 with ~40% collapsed to ~1 -- statistically the same bimodal lottery as
cap16. correlate-all is strictly worse (collapses 2/3, lnZ 11 nats low). So no single-run
config is a posterior on this high-SNR best-fit point; the robust recipe is MANY copies
pooled by reliability (the reviewer's original point, now on data).

Harness: bench_onsource_ensemble.sh (portfolio must be selected explicitly -- the driver
default adaptive_cartesian_gpu is NOT the portfolio/AV) + compare_extrinsic_breadcrumbs.py
(weight-correct per-group posterior via --extrinsic-proposal-output; reliability-weighted
vs naive pooling; collapse detector = out-of-bounds degenerate GMM). Weight-correct export
unblocked by PR #35 (cherry-picked).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@oshaughnessy-junior

Copy link
Copy Markdown
Owner Author

Auto-review: not ready to merge while CI is red.

The three failed jobs (docs, install (3.10), install (3.11)) have empty step metadata and their GitHub logs are unavailable (404), so I cannot attribute the failure to this change; the simultaneous pre-step failures look runner/service-side rather than a test assertion. Please rerun CI and require a green result.

Local review: clean merge with rift_O4d; changed Python compiles; the focused test_portfolio_oracle.py completes under the project’s optional-plugin-isolation setup. The direct unisolated run remains blocked by the pre-existing eager NF entry-point import when torch is absent (already tracked separately). The required base-vs-candidate integrator shape gate is running; I will update this review with that result.

@oshaughnessy-junior

Copy link
Copy Markdown
Owner Author

Integrator-gate update: this PR cannot yet satisfy the mandatory portfolio shape gate. The candidate run reports ModuleNotFoundError: No module named 'torch' for every portfolio row, due to the eager optional-NF entry-point import. That is the unresolved optional-plugin-isolation issue tracked in #33, but it makes a base/candidate comparison non-probative for this portfolio-changing patch.

Please merge or depend on the #33 isolation fix, then rerun the standard CPU base-vs-candidate gate (with portfolio strict) and rerun CI. Until then, the red CI plus invalid portfolio gate block merge.

@oshaughnessy-junior

Copy link
Copy Markdown
Owner Author

Closing as stale/already upstream.

@oshaughnessy-junior
oshaughnessy-junior deleted the claude/jovial-lichterman-222363 branch August 1, 2026 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant