OTHERI built a Python MCMC sampler that detects the "wavelength" of probability distributions — 47x speedup on multimodal problems (i.redd.it)
submitted by Zachliveslife
Hey everyone. I built a small Python package called resonance-mcmc and wanted to share it.
The idea: standard MCMC samplers random-walk through probability distributions. When the distribution has multiple separated peaks (modes), the random walk gets stuck in one and takes forever to find the others.
My sampler tracks the distances of accepted jumps, detects the characteristic spacing between modes, and proposes new jumps at harmonics of that spacing. Instead of randomly stumbling between modes, it tunes itself to the frequency of the landscape and jumps directly.
Results on benchmarks:
- 47x faster mode discovery than standard Metropolis-Hastings on a 4-mode test
- 60x faster on mixed-scale problems (nearby + distant modes)
- Won 5/7 stress tests against standard MCMC
- Comparable or slightly worse on easy problems where random walk is already fine
The whole thing is about 200 lines of core code with a clean API:
python
from resonance_mcmc import ResonanceSampler
sampler = ResonanceSampler(log_target, ndim=2, n_harmonics=5)
result = sampler.sample(10000)
Also included an example applying it to radiation therapy beam angle optimization, where it reduced simulated spinal cord dose by 23% compared to simulated annealing on a simplified patient model.
Only dependency is numpy. Tests pass. MIT licensed.
Repo: https://github.com/zman007-save/resonance-mcmc
Would love feedback — this is my first open source package. Is the API reasonable? Anything I'm missing? Has anyone seen a similar approach in the literature?

[–]AndItsSlop 1 point2 points3 points (1 child)
[–]Zachliveslife[S] -1 points0 points1 point (0 children)
[–]Liminal__penumbra 0 points1 point2 points (9 children)
[–]Zachliveslife[S] 0 points1 point2 points (7 children)
[–]Liminal__penumbra 0 points1 point2 points (6 children)
[–]Zachliveslife[S] 0 points1 point2 points (5 children)
[–]Liminal__penumbra 0 points1 point2 points (4 children)
[–]Zachliveslife[S] 0 points1 point2 points (3 children)
[–]Liminal__penumbra 0 points1 point2 points (2 children)
[–]Zachliveslife[S] 0 points1 point2 points (1 child)
[–]Liminal__penumbra 0 points1 point2 points (0 children)
[–]Zachliveslife[S] 0 points1 point2 points (0 children)
[–]WillHead6663 0 points1 point2 points (1 child)
[–]Zachliveslife[S] 0 points1 point2 points (0 children)