Skip to content

Add Molewhacker importance sampler - #579

Draft
BJMCox wants to merge 17 commits into
mainfrom
whack-a-mole-sampler
Draft

BJMCox wants to merge 17 commits into
mainfrom
whack-a-mole-sampler

Conversation

@BJMCox

@BJMCox BJMCox commented Sep 9, 2026 •

Copy link
Copy Markdown
Member

Adds standalone MolewhackerSampling with local Fisher geometry and Newtrinos-style proposal updates. Uses fresh importance samples, parallel mixture scoring, and separate controls for adaptation and production ESS.

Three defaults depart from the source algorithm:

  • Each seed gets a second Gaussian with the observed information as precision. Fisher information degenerates where the forward model is stationary, such as a mixing angle near maximal mixing. A Newton step at each seed finishes a mode search that stops after 50 iterations.
  • After adaptation stops, three fresh rounds add draws from the current proposal to the pool before selection. Otherwise the pool holds few draws from the current proposal and misses the ratio spikes that production draws hit.
  • The fresh-round draws then refit the proposal by importance-weighted EM (MitISEM style). The held-out weighted log-likelihood picks one to six Gaussians, and their covariances are inflated by 1.1 to bound the tail weights. They take 80% of the mass, and the adaptive mixture keeps 20% for defence. Center-ratio masses cannot see proposal mass placed where the target is small. These draws can. No extra target calls.

laplace_seeds = false, fresh_rounds = 0 and refit = nothing restore the source behaviour. MolewhackerRefit holds the fit settings. Production draws always come from the final frozen proposal. Results also report the Pareto tail shape of the weights and the largest normalized weight, with optional Pareto smoothing.

On the public DeepCore model (four seeds, 20 rounds, 4,000 output draws, mode search included), the first two changes raise ESS per second from 0.03–2.6 to 5.1–5.8 and cut the largest share of the squared weights from 0.10–0.995 to 0.05–0.11. The EM refit adds 13–36% production ESS on DeepCore (two seeds, three production repeats each) and 13–210% on six 12-dimensional test targets. On DeepCore the inflation cuts the largest weight share from 0.18–0.21 to 0.07–0.08.

Pool scores are cached across rounds, so each round whitens only new points and components. ncandidates defaults to 14, independent of the thread count.

Validated with analytic checks, Julia 1.10/1.13 tests, a documentation build, JET, PProf, and public DeepCore comparisons. The new defaults change fixed-seed results. The private reported workload still needs a collaborator rerun.

Fit a defensive Gaussian mixture with local Fisher geometry, learned component masses, and independent validation. Freeze the proposal before fresh production draws so returned importance weights use their generating density.
@codecov

codecov Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.64087% with 54 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.96%. Comparing base (3ab3baf) to head (e844d50).

Files with missing lines Patch % Lines
src/samplers/importance/molewhacker.jl 94.13% 31 Missing ⚠️
src/samplers/importance/molewhacker_geometry.jl 78.43% 22 Missing ⚠️
ext/BATOptimizationLBFGSBExt.jl 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #579      +/-   ##
==========================================
+ Coverage   69.19%   71.96%   +2.76%     
==========================================
  Files         123      126       +3     
  Lines        7230     7873     +643     
==========================================
+ Hits         5003     5666     +663     
+ Misses       2227     2207      -20     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Batch proposal densities and reuse validated unit-scale precision factors while preserving scalar precision and tail behavior. Add optional bounded Fisher-gradient center refinement with counted target calls, fresh validation, and unchanged production weights.
Remove duplicate statistical checks and diagnostic snapshots while retaining the distinct sampler contracts. Use smaller fixtures and exact oracles where they preserve scientific coverage.
Cache the unchanged zero-mass endpoint only when a round fits a candidate. Score endpoints directly while preserving promotion, reduction order, and RNG behavior.
Match Newtrinos initialization and mixture updates while retaining fresh proposal-correct output weights. Reuse exact geometry and remove the fixed output count and mandatory prior fraction.
Score canonical Gaussian mixtures in bounded parallel blocks and update center densities incrementally, preserving the source proposal law.
Restore explicit pool ESS and efficiency thresholds so a production ESS goal no longer doubles as a fitting-pool threshold.
Allow users to limit concurrent target and geometry work without changing sampler candidates. Apply the same cap to mixture-scoring partitions while retaining the current default.
Store each reselected pool component once and retain its multiplicity in fitting weights and draw allocation. Preserve the proposal law and refinement budgets while reducing mixture scoring work.
Laplace Gaussians at the seeds use the observed information as precision.
They capture curvature that Fisher information misses where the forward
model is stationary. A Newton step polishes each seed, so the default mode
search now stops after 50 iterations. Laplace seeds are on by default.

Discovery batches come only from new components, so the pool holds few
draws from the current proposal and misses its ratio spikes. Three fresh
rounds now follow any adaptation stop by default. Each round first adds
batchsize draws from the current proposal to the pool.

Results report the generalized Pareto shape of the production weights,
and optional Pareto smoothing is available. Results count proposed and
stored components separately. Idle tasks share Jacobian columns when few
geometries are pending. The sequential executor checks its output length,
as main does from #558. The internal API manual lists MultiThreadedExec.
Pool scoring keeps each component's log density at each pool point, so a
round whitens only new points and new components. On the synthetic
stationary target, runs take 40% less time with identical results. Above
2^24 cached entries, scoring recomputes all densities as before.

ncandidates now defaults to 14 instead of the thread count, so results do
not depend on the machine. Type assertions on the seed RNG, the optimizer
result, and the Gram matrix remove runtime dispatch that JET reported.
Center-ratio masses see the target only at component centers, so they
cannot see proposal mass placed where the target is small. After the
fresh rounds, importance-weighted EM in the style of MitISEM fits one to
six Gaussians to those draws, each weighted by the proposal that drew it.
The number maximizes the weighted log-likelihood of held-out draws, and
the refit on all draws starts from the held-out winner. The final
proposal gives the fit 80% of the mass and keeps the adaptive mixture at
20% for defence. It needs no extra target calls.

On six 12-dimensional test targets, production ESS rose by 20-229%. On
the public DeepCore model it rose by 19% and 36% over two seeds, against
3% and 17% for a fixed three Gaussians.

MolewhackerRefit holds the fit settings. Pass refit = nothing to keep the
adaptive mixture. laplace_inflation replaces a fixed constant. Results
report max_weight, the inverse of the L-infinity effective sample size,
which flags one dominant weight. The discovery pool and fresh draws grow
as ElasticArrays, and the round history is a StructArray.
@BJMCox
BJMCox force-pushed the whack-a-mole-sampler branch from e91032e to a76353a Compare September 23, 2026 19:10
The weighted EM fit gives the target's own covariance, so weights in the
target's tails stay unbounded. MolewhackerRefit now inflates each fitted
covariance by 1.1, which bounds the weights where the tails are Gaussian.

On six 12-dimensional test targets, this cost about 6% production ESS and
cut the mean Pareto shape from 0.15-0.32 to -0.02-0.25. On the public
DeepCore model, over three production repeats per seed, ESS changed by
-1% and -4%, the largest weight share fell from 0.18-0.21 to 0.07-0.08,
and the largest Pareto shape fell from 0.43-0.49 to 0.35-0.36. On three
48-dimensional targets the fit underestimates the covariance, and the
inflation raised ESS by 7-23%.

Student-t components (MitISEM) with five degrees of freedom gave similar
tails at 25% lower ESS. Estimated degrees of freedom went to the bound.

This branch has not been deployed

No deployments
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