Repository navigation
Add nets.IsingEnergy and a discrete Ising GWG example - #16
Merged
Merged
Conversation
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
nets.IsingEnergy is the library's first discrete/lattice energy: a 2D nearest-neighbor Ising energy E(x) = -J sum s_i s_j for binary (B, H, W) data (spins s = 2x - 1), with an optional learnable coupling. examples/train_ising.py samples it with GibbsWithGradients at three coupling strengths and shows the ferromagnetic phase behavior (neighbor agreement 0.55 -> 0.73 -> 0.91). Tests: agreement rises with coupling, output shape, and gradient flows to a learnable coupling. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
davidkhjo
force-pushed
the
ising-example
branch
from
August 9, 2026 06:46
ecdf866 to
afe5eb1
Compare
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.
The
GibbsWithGradients/CategoricalGibbsWithGradientssamplers are exact and closed-form-validated but had no example — and the library shipped no discrete/lattice energy to run them on. This adds both.nets.IsingEnergy— the library's first discrete/lattice energy: a 2D nearest-neighbor Ising energyE(x) = -J Σ_⟨i,j⟩ s_i s_jfor binary(B, H, W)data (spinss = 2x − 1), differentiable in the relaxed input (what GWG needs). CouplingJis a learnablenn.Parameterwhenlearn_coupling=True, a fixed buffer otherwise.examples/train_ising.py— samples a 2D lattice withGibbsWithGradientsat three coupling strengths, reproducing the ferromagnetic phase behavior:Neighbor agreement rises 0.55 → 0.73 → 0.91 as coupling goes 0.1 → 0.4 → 1.0.
Tests
test_ising_energy_orders_with_coupling(agreement increases with J, strong ferromagnet nearly aligned),test_ising_energy_shape_and_learnable_coupling(shape, buffer-vs-parameter, gradient flows to J). Docs: new "Discrete EBMs" section inexamples.md, pointer fromsampling.md.🤖 Generated with Claude Code