Jax: Fast Combinations Calculation (github.com)

🤖 AI Summary
A compact JAX implementation uses the combinatorial number system (a “combinadic”) to generate k-combinations from an integer index extremely efficiently. The code maps every integer m in [0, C(n,k)-1] to its k-combination by computing its mixed-radix combinadic digits (based on binomial coefficients) and then converting those digits to element indices. A small example (n=4, k=3) reproduces itertools.combinations output; the implementation computes actual = n-1 - calculateMth(n,k,totalcount-1 - arange(...)) to vectorize and invert the lexicographic ordering so all combinations are produced in parallel on accelerators. This matters for AI/ML workflows that need massive, parallel enumeration or random access to combinatorial subsets—feature subset selection, combinatorial augmentation, subgraph motifs, or batched search—because it avoids Python-level loops and leverages JAX’s JIT/vectorization and GPU throughput. Key technical points: the combinadic is an integer representation with a variable base given by binomial coefficients; converting m → combinadic is done by iteratively subtracting the largest binomial term to form digits, then mapping digits to indices. Practical limits include 64-bit integer range (so extremely large C(n,k) can exceed representable indices) and the usual combinatorial explosion, but for many medium-scale combinatoric tasks this yields orders-of-magnitude speedups when run on a single GPU.
Loading comments...
loading comments...