Skip to content

Curveball: trade distinct column pairs; cache trading columns in the generator - #9

Open
mkborregaard wants to merge 2 commits into
mainfrom
mkb/curveball-distinct-pairs
Open

mkborregaard wants to merge 2 commits into
mainfrom
mkb/curveball-distinct-pairs

Conversation

@mkborregaard

@mkborregaard mkborregaard commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

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

mkborregaard and others added 2 commits November 2, 2026 16:32
…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>
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