Repository navigation
Curveball: trade distinct column pairs; cache trading columns in the generator - #9
Open
mkborregaard wants to merge 2 commits into
Open
mkborregaard wants to merge 2 commits into
mkborregaard wants to merge 2 commits into
Conversation
…generator Draw the two columns of each trade without replacement, as in the paper's R and Python scripts. Pairing a column with itself is a no-op, so drawing with replacement wasted 1/C of the trades (a third on a 3-column matrix). The generator now stores the columns that can trade, which never change along the chain, so a draw no longer scans every column; the buffer size is taken from those columns too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Two small changes to curveball, following a comparison with Strona et al. (2014) and their R and Python scripts.
Distinct pairs. Both columns of a trade were drawn independently, so a column could be paired with itself, which does nothing. That wasted 1/C of the trades: a third on a 3-column matrix, under 2% at 60 non-empty columns. The pair is now drawn without replacement, as in the paper's scripts. On the paper's 3×3 example (all margins [1,2,1]), the one-trade transition matrix now matches the scripts' rule to within simulation noise (0.0025), and reaching the closeness to uniform of the paper's Table 3 takes 10 pair extractions instead of 16.
Cached columns. The columns that can trade never change along the chain, so the generator now finds them once and stores them in
CurveballSampler, and the buffer size is taken from those columns. On a 6×17542 matrix with 60 occupied cells, a generator draw went from about 29 µs to 15 µs; the fixed per-call cost is now under 0.1 µs.randomize_matrix!is unchanged and still finds the columns on each call.The target distribution is unchanged, but draws for a given seed differ from 0.2.1, so this bumps the version to 0.2.2.
All 40 tests pass.
🤖 Generated with Claude Code