Skip to content

Changelog

0.9.0 (2026-12-05)

New: torchtsetlin.datasets. Datasets now have their own namespace, next to torchtsetlin.data for the operations on data (encoders, splits, wrappers, GraphBatch), as in torchvision.datasets. It holds the new downloadable benchmarks below, the generators (make_noisy_xor, make_shapes, make_scenes, ...) and the torchvision loaders (load_mnist_boolean, ...). Nothing breaks: the generators and loaders remain importable from torchtsetlin.data as before (same objects), and the documentation now uses tt.datasets..

New: benchmark datasets that download on first use (issue #54). torchtsetlin.datasets loads the 15 benchmarks of TM-MCAF (arXiv 2612.01468) like torchvision datasets: the first use with download=True fetches the original files (SHA-256 checked) into root/<Name>/raw/ and writes a processed cache; later uses read the cache. root defaults to $TORCHTSETLIN_DATA or ./data. New classes: HIGGS, Electricity, MagicTelescope, PhishingWebsites (OpenML), BayesianNetworkDataset (bnlearn pigs / hailfinder networks, forward-sampled locally, with markov_blanket()), IMDB and Reuters (the Keras word-index files, with Keras's load_data rules) and BooleanImageDataset (MNIST, Fashion-MNIST and KMNIST through torchvision, thresholded at 75). Each uses the paper's Booleanization by default and fits it on the training split only; encoder= replaces it with any encoder (a copy is fitted on the training split, categorical columns stay one-hot, text encoders get padded word-index batches). Also new in torchtsetlin.data: QuantileOneHotEncoder (the bins of scikit-learn's quantile KBinsDiscretizer, one-hot, with categorical columns), stratified_split and random_oversample. No new dependency; the image datasets need the vision extra. Guide: Guides → Benchmark datasets; example: examples/tm_mcaf_datasets.py.

0.8.6 (2026-12-04)

Fix: large Conv3d* models stay on the fused CUDA path (issue #17). The patch block of the dense path charged the model's own (C, 2F) include mask (2·C·L) against the per-chunk budget, so with the default max_chunk_elements moderately large 3D models evaluated one patch per block and one example per chunk, and any split also took them off the fused Triton path (orders of magnitude slower training; e.g. kd=4, 8 000 clauses per class). The fused path now ignores the dense block (it keeps no (P, C) intermediates; only an explicit patches_per_chunk < P keeps a model off it), the dense accounting no longer charges the include mask, automatic blocks are at least 16 patches, and a one-time warning names max_chunk_elements when the dense block falls below P/8 or a CUDA batch does not fit one fused chunk. One-block models are unchanged; learning was never affected, only speed (and the random draw order of models that used to be blocked).

Fix: graph TM CUDA graphs keep full and padded batches apart (issue #35). A depth-1 update captured for a batch whose graphs fill every node slot (GraphBatch.full_nodes, bit-packed evaluation without a node mask) was replayed for a padded batch of the same shape, so all-zero padding nodes could match clauses and receive feedback. full_nodes is now part of the capture key. Affected: depth-1, single-node-type GraphTsetlinMachine training on CUDA with Triton and CUDA graphs on, when one padded shape saw both full and partly padded batches; such models should be retrained. cuda_graphs = False was a workaround.

Fix: BitPlaneEncoder honours channel_dim (issue #47). The argument was stored but ignored: inputs with 3 or more dimensions always had their bit planes stacked into dimension 1, so channel-last images (N, H, W, C) with channel_dim=-1 came out as (N, H*n_bits, W, C) with the planes mixed into the height axis, without an error. The planes now go into channel_dim ((N, H, W, C*n_bits) for channel-last), and a channel_dim that is the batch dimension or out of range raises a ValueError. The default channel_dim=1 gives the same output as before.

Fix: PyramidEncoder accepts even patch sizes (issue #46). Padding patch // 2 on every side made each level one row and column too large for an even patch, and forward failed with a reshape error. Even patches are now padded like PyTorch's padding="same" ((patch - 1) // 2 before, patch // 2 after), so the output has the documented shape and agrees with output_size. Odd patches are unchanged.

Fix: Trainer.evaluate / Trainer.predict leave the model in the mode it was in (issue #41). evaluate (and the segmentation branch of predict) ended with an unconditional model.train(), so evaluating an eval()-mode model switched it to training mode and changed its later predictions (empty clauses vote while learning). The other predict branches left a training model in eval(). Both now restore the caller's mode, also when they raise. Training is unaffected: fit sets train() every epoch and update does not depend on the mode.

Fix: linear predict_proba is a distribution when every class is at -T (issue #42). The linear mapping (1 + v/T)/2 is 0 for every class at or below -T, and such rows came back as all zeros. They now get the uniform distribution; every other row is unchanged. The mapping is the new functional.linear_proba_from_votes, used by TsetlinMachine (and its conv variants) and multi-class CoalescedTsetlinMachine; multi-label per-output probabilities and method="softmax" are unchanged.

Fix: dropout masks follow the model to another device (issue #43). model.to(device) moved the sampled literal-dropout mask only for literals="positive"/"negated" and never moved the clause-dropout mask, so with drop_granularity="epoch" the next update after a CPU/CUDA move failed with a device mismatch. Both masks now move with the model, keeping the epoch's sampled pattern.

Fix: integer encoders and regression datasets accept CUDA tensors (issue #38). OneHotEncoder.fit/forward, BitPlaneEncoder, HypervectorEncoder and BooleanTensorDataset(..., regression=True) passed every input through NumPy and raised TypeError for CUDA tensors. Tensors are now used directly (moved with the same safe copy as the other encoders). BitPlaneEncoder has no buffers and encodes a tensor on its own device.

Fix: regression checkpoints keep the target range (issue #39). A range inferred from the first batch (y_range=None) was not in the state_dict, so a loaded model could not predict and resumed training on a newly inferred scale. RegressionTsetlinMachine (and its conv variants) now save the range as module extra state (_extra_state, exact floats, weights_only loads work). Older checkpoints still load, also with strict=True, and keep the model's current range, as does a checkpoint saved before any update.

Fix: load_state_dict rejects checkpoints of another shape (issue #40). Mismatching buffers were resized to the checkpoint while n_features, clause and class counts stayed, so the load reported success and the next forward call failed. Such checkpoints now raise PyTorch's size mismatch error. Lazy models (n_features=None) are still materialised from a checkpoint with the same clause count.

0.8.5 (2026-12-03)

Same changes as 0.8.4, which was tagged but never published (its test run failed on the CI runners, see the load_segmentation_boolean entry below).

0.8.4 (2026-12-03, not published)

Fix: full-resolution segmentation targets are sampled at the patch centres (issue #36). Input-resolution label maps (and multi-label masks) were mapped to the output grid with y[::sh, ::sw] from pixel 0, which is the patch centre only when padding == patch_size // 2. With any other padding (e.g. padding=0) the models learned from, and the Trainer scored against, labels shifted by patch_size // 2 - padding pixels; such models should be retrained and their metrics are not comparable. Targets are now taken at the centre pixel of each patch. When the padding exceeds the patch radius the outer centres leave the image and input-sized targets raise a ValueError (was a reshape crash); pass targets on the output grid. Multi-label masks of a wrong size now raise as single-label maps do. The default padding="same" with an odd kernel is unchanged for any stride.

Fix: padding="same" rejects an even patch_size (issue #45). It produced an output grid one row/column larger than the input, so update failed with a reshape error. It now raises a ValueError at construction; use an odd kernel or an explicit padding.

Fix: position literals of segmentation models are named by the thresholds they encode (issue #44). With an integer position_encoding the bits use evenly spread thresholds, but clause_expression / default_feature_names / pixel_feature_names printed y>k with the bit index k. Names now give the bound the model evaluates and agree with clause_region. Only printed names change; position_encoding=True is unaffected.

Fix: Trainer custom metrics on segmentation models. Single-label models: custom metrics no longer receive pixels equal to the model's ignore_index (issue #50), so they see the same pixels as the built-in metrics; custom metrics computed before on data with ignored pixels are not comparable. Multi-label models: custom metrics were silently skipped (issue #48) and are now called with (N, K) bool predictions and targets, so val_<name> reaches the logs and the callbacks that monitor it.

Fix: load_segmentation_boolean reads each sample once (issue #37). It indexed the dataset twice per sample, so with random joint transforms the image and the mask came from two different draws (misaligned pairs), and deterministic datasets were decoded twice. It now imports torchvision only to resize or to read PIL images, so tensor datasets load without it.

0.8.3 (2026-11-30)

Fix: metrics.boundary_f1 with ignore_index no longer reads the prediction at ignored pixels (issue #32). The function copied the prediction into the ignored pixels of the target before it looked for boundaries and masked those pixels afterwards. The copied label had by then decided whether the neighbours of an ignored pixel were boundary pixels, so two predictions that differed only at ignored pixels got different scores, and a boundary error next to an ignored region could be scored as correct (the example of the issue: 1.0 and 0.8 for the same error). A boundary is now an adjacency between two pixels that both count: an ignored pixel is no boundary pixel and gives its neighbours none, in the prediction and in the target. Scores computed with ignore_index on targets that contain ignored pixels change (they were too high where they differ); calls without ignore_index return exactly what they did. No change to any model: training and prediction are as in 0.8.2.

0.8.2 (2026-11-29)

The Trainer no longer waits for the GPU after every batch (issue #31). Trainer.fit kept its running batch_accuracy / batch_mae as Python numbers, which read a value back from the device, and so waited for the whole update, once per batch. The running sums now stay on the device and are read back once per epoch. MNIST on an RTX 3090 through Trainer.fit: 0.74 s → 0.61 s per epoch (TsetlinMachine, 100 clauses per class, batch 32), 1.96 s → 1.59 s (2 000 clauses per class) and 0.50 s → 0.39 s (FuzzyTsetlinMachine, 20 clauses per class, batch 50). The logged values are the same. Also: the multi-label segmentation evaluation and metrics.regression_metrics / metrics.multilabel_metrics read their results back once, and the label check of the segmentation models costs one readback per update instead of three (it still raises a ValueError for a bad label). Training on the CPU and code that calls model.update directly are unaffected.

0.8.1 (2026-11-29)

FuzzyTsetlinMachine gets its fast paths, its interpretation tools and its documentation (issue #29). The learning rules are those of 0.8.0; the other models are unchanged.

  • CUDA: updates replay as CUDA graphs. The model's commit on CUDA is now one dense pass without host synchronisation (functional.commit_fuzzy_dense), so batched updates and sequential blocks are captured and replayed like those of the other models, without Triton. MNIST with 20 clauses per class on an RTX 3090: 2.0 s → 0.3 s per epoch at batch 50, and 68 s → 8 s per epoch in sequential mode. With 200 clauses per class: 2.4 s → 1.0 s and 72 s → 46 s. Models above dense_commit_max_elements automata, and models with dropout, update only the clauses that received feedback.
  • CPU: sparse forgetting. Clauses whose only feedback is forgetting are updated by an exact sparse draw, and counts are written only for the clauses with events (sequential mode on 16 threads: about 300 → 1 000 examples per second at 20 clauses per class).
  • Reading a fuzzy model. rules() prints the tolerance (IF fewer than 8 of (...) fail THEN 3), explain_clause(x, clause) lists the literals of one clause that hold and that fail for one input and its vote, and interpret.explain, clause_activity and clause_precision accept fuzzy clause outputs (an output above 0 counts as a match; an explanation weights a clause by its output). Their results for the other models are unchanged.
  • Docs. A concept page (Fuzzy clauses), examples/mnist_fuzzy.py, and the notebook Fuzzy clauses on MNIST (20 clauses per class next to the ordinary machine with 2 000).

0.8.0 (2026-11-29)

New model FuzzyTsetlinMachine (issues #26 and #29): the Fuzzy-Pattern Tsetlin machine of Tsetlin.jl (arXiv:2508.08350) for flat inputs.

  • Fuzzy clause output. A clause votes max(0, max_failed_literals - failed), where failed counts its included literals that are False, so a long clause still votes, with less weight, when a few of its literals fail. max_failed_literals=1 is the ordinary 0/1 output.
  • Feedback to fit. On a matching clause, Type I moves every True literal towards inclusion and every excluded False literal away from it, both with probability 1; included False literals are not touched. On a clause that does not match, every literal is forgotten with probability 1/s (the only use of s, hence values of 200 to 2 000). Type II is the standard rule. max_included_literals is a gate on the inclusion steps (nothing is reverted, and Type I does not turn into forgetting). Every class learns from every example (negative_classes="all"; "one" draws a single negative class).
  • Same interface as the other models. Batch and sequential mode, CPU and CUDA, literals=, dropout, lazy n_features, state_dict, rules(). New functional pieces: functional.fuzzy_clause_outputs and functional.apply_fuzzy_feedback.
  • Measured (the maintainers' experiment records, one seed, 100 epochs, batch 50): 97.53 % on MNIST with 20 clauses per class and 98.41 % with 200; 88.08 % and 89.31 % on Fashion-MNIST. The standard machine at its best known setting with 2 000 clauses per class reaches 97.55 % and 88.80 % in the same harness. Single examples follow a per-example port of Tsetlin.jl's feedback! state for state (tests/test_fuzzy.py).
  • Limits of this first version. It commits with one eager routine and does not use the compiled kernels, the Triton commit or CUDA graphs yet: about 2 s per MNIST epoch at batch 50 on an RTX 3090, but about 70 s in sequential mode. No clause weights, no convolutional or regression variant, and the include limit stays at the midpoint.

The existing models are unchanged: they train and predict exactly as in 0.7.4.

0.7.4 (2026-11-23)

New option literals: restrict a clause to one kind of literal (issue #23). Every model accepts literals="both" (default, unchanged), "positive" (only x_k) or "negated" (only NOT x_k). Literals of the other kind start excluded and never receive feedback, so they are never included; evaluation, votes, weights and the literal budget are unchanged. "negated" on a one-hot input makes a clause reason by elimination, the setting of implementations that feed the negated input without appending negated literals. The restriction runs on the same update paths as an unrestricted model (CUDA graphs and the fused kernels stay on), ta_state keeps its (C, 2F) shape and the checkpoint format does not change. Loading a state that includes a switched-off literal raises a ValueError. Models built without the argument train bit for bit as before.

0.7.3 (2026-11-20)

No change to the learning code: models train and predict exactly as in 0.7.2.

The title follows the paper, which is now torchtsetlin: Fast, Interpretable Tsetlin Machines for PyTorch: the package description (PyPI), the module docstring, the README, the documentation home page and site description, CITATION.cff and the BibTeX entries. The technical report and the white paper are rebuilt with this title; their content still describes version 0.3.2.

0.7.2 (2026-11-19)

No change to the learning code: models train and predict exactly as in 0.7.1.

The package now carries the paper's title, torchtsetlin: Fast, Interpretable Tsetlin Machines for the PyTorch Ecosystem, in the package description (PyPI), the module docstring, the documentation home page and the site description.

New benchmark page: Batch size × clauses (docs/batch-size-clauses.md). 128 MNIST runs over batch sizes 1 to 1024 and 1,000 to 64,000 clauses per class, for flat, convolutional and 3D convolutional models, with accuracy and GPU-time heatmaps, a time-against-error plot, full tables and two controls (fixed T, sequential mode). Batches of 16 to 64 are both the most accurate and the cheapest setting; a batch of 1024 loses accuracy on every model and does not save time. The page and its figures are generated from the experiment's run records.

0.7.1 (2026-11-10)

Fix: out of memory on large models when counting included literals. Every refresh of include_count (the dense CUDA commit, apply_feedback* with a clause budget, and the full include-cache refresh after loading or moving a model) summed state >= N in one go, which makes an int64 copy of the whole state: 8 bytes per automaton, a 7.5 GiB spike at 64,000 clauses per class on flat MNIST (640,000 x 1,568 automata). Flat MNIST at that size ran out of memory on a 24 GB RTX 3090 for batches of 64 and more. The new functional.count_included counts in row blocks (at most ~0.6 GiB of scratch, same speed, same result) and is used at every such site. Found by the batch-size x clause-count experiments (gap MBC-1; also toolbox_cifar10 TB-1).

Notebooks in the documentation, runnable in Google Colab. The example notebooks (examples/notebooks/) are rendered under Examples → Notebooks (mkdocs-jupyter, added to the docs extra; docs/examples/notebooks is a symlink to them). They are stored without outputs, nothing is executed during the docs build, and every notebook was re-run on 0.7.0 with its text updated to the results it now produces. Each notebook has an Open in Colab badge and a first cell that installs torchtsetlin from PyPI when it runs in Colab; MNIST and CIFAR-10 download to data/ there. New notebook 06_graph_tsetlin.ipynb: the graph Tsetlin machine on the paper's three-A's task (four readable clauses, explain_node), run lengths, the padded CUDA fast path, and MNIST as depth-1 graphs learning bit for bit like ConvCoalescedTsetlinMachine. New notebook 07_segmentation_tsetlin.ipynb: SegmentationTsetlinMachine on generated street scenes (the segmentation example), with the row-prior floor, position literals and the OR-pooled pyramid, explain_pixel, a patches_per_commit sweep and class-balanced feedback. The segmentation example, guide and concept pages now show the numbers measured on 0.7.0 (e.g. single scale 0.818 mIoU, was 0.798; pyramid + position 0.954, was 0.959).

The C-RTM notebook (04_convolutional_regression_tsetlin.ipynb) no longer recovers the planted mask with the paper's 15 clauses (0 of 12 restarts, was 9 of 12 on 0.1.x). Side experiments trace this to the two 0.5.0 rule changes together: weights floored at 1 and the squared regression feedback (either one alone still breaks it, putting both back restores it). The notebook now uses 8 weighted clauses, 400 epochs and batches of 16, which is exact on 8 of 12 restarts.

0.7.0 (2026-11-08)

New: graph Tsetlin machine (GraphTsetlinMachine, torchtsetlin.data.GraphBatch, torchtsetlin.data.SymbolTable; Granmo et al., arXiv:2507.14874; issue #8, torchtsetlin_plans/plans/graph-tm.md). Deep clauses over graphs with typed edges: one clause component per layer, connected by messages that clauses send to neighbouring nodes. Random, double-hashed or one-hot messages, node types, batched and sequential feedback, and clause decoding in the paper's right1:0 notation. At depth 1 on GraphBatch.from_images graphs it learns bit for bit like ConvCoalescedTsetlinMachine (tested). The Trainer accepts a GraphBatch wherever it takes a tensor. A specificity per layer (s=(s0, s1, ...), as the reference implementation allows; new functional.apply_feedback_blocks), explain_node (traces a clause at one node back to the symbols of the neighbours that sent its messages) and rules(symbols=...).

Graph TM on the CUDA fast paths (torchtsetlin_plans/plans/graph-tm-fast-paths.md). GraphBatch.pad(max_nodes, max_edges) gives a fixed-shape layout (edges as a (B, E, 2) array with a mask) whose slices have static shapes and never synchronise with the host. Batched updates run in events mode (the fused Triton commit) for flat and padded batches. Padded batches also take the compiled single-example commit in sequential mode and are replayed from CUDA graphs. Sequence example on an RTX 3090 (smoke): sequential 4.8 → 0.065 ms per graph, batched 0.23 → 0.013 ms per graph. models/base.py and the Triton kernels are unchanged.

Depth-1 graphs on the convolutional kernel. A depth-1 graph clause is a convolutional clause over the node features, so batches whose graphs all have the full node count (GraphBatch.full_nodes, set by from_images and from_graphs, kept by slicing) evaluate and draw their feedback nodes with _triton.conv_eval on bit-packed literals, never forming the (B, P, C) match tensor. On CUDA such a model learns bit for bit like ConvCoalescedTsetlinMachine (tested). This makes the paper-scale image experiments feasible: Fashion-MNIST with 40,000 clauses trains in ~12 s per epoch on an RTX 3090.

CoalescedTsetlinMachine.rules forwards extra keyword arguments to clause_expression.

Paper reproduction (the maintainers' experiment records, 5 seeds each): three consecutive A's 100.00 (paper 100); MNIST GraphTM 98.07 (98.42), CoTM 98.49 (98.93); Fashion-MNIST GraphTM 88.59 (89.49), CoTM 90.70 (91.05). All within tolerance, and the paper's ordering CoTM > GraphTM holds. CIFAR-10 and multivalue noisy XOR were skipped (no comparable published number).

0.6.1 (2026-11-01)

Fix: sequential convolutional models on CUDA predicted from a stale include mask (gap G25 of the cross-library benchmark). In 0.6.0, once all of a sequential model's 64-example update blocks were replayed from CUDA graphs, nothing marked the bit-packed include mask stale, so predict() / forward() on a Conv* model trained with feedback_mode="sequential" kept using the mask from its last eager update. Learning itself was correct; the predictions froze (2-D Noisy XOR: 78.5 +- 13.4% over 5 seeds against 100% on 0.5.1). A replay now re-applies the Python-side flags its captured update set. Batched updates, flat models and the CPU were not affected. On 0.6.0, model.cuda_graphs = False or TORCHTSETLIN_CUDA_GRAPHS=0 avoids it.

0.6.0 (2026-10-28)

The CUDA path is rebuilt around two Triton kernels and CUDA graphs (gaps G15-G24 of the low-level kernel audit). What a model learns is unchanged in distribution, and CUDA-graph replays are bit-identical to eager execution. Same GPU (RTX 3080), per update() against 0.5.1: flat MNIST batch 32 4.7 -> 1.1 ms, batch 100 5.1 -> 1.7 ms; IMDb-sized flat model 20.7 -> 6.6 ms; convolutional MNIST batch 16 5.0 -> 1.5 ms, batch 100 22.7 -> 7.6 ms; Noisy XOR sequential 17x and 2-D Noisy XOR sequential 12x faster; convolutional prediction 4.7x faster.

  • Fused commit kernel (torchtsetlin._triton.fused_commit; G15, G16, G17, G22). A batched CUDA update that fits one chunk records its events instead of count tensors; one kernel computes the Type Ia / Type II counts per tile (tensor cores for flat models, a gather of each clause's random matching patch for convolutional ones), samples them (inverse CDF, walked arithmetically for small counts), and writes the state, the include cache, the bit-packed include mask and the include counts. No (C, 2F) count buffer is allocated, saving 12 bytes per automaton.
  • Fused convolutional evaluation (_triton.conv_eval; G20, G21, G24). Clauses are evaluated on bit-packed literals with the OR over patches in registers; while learning the kernel also draws each clause's random matching patch for Type Ia and, independently, Type II. Conv literals are float16 on CUDA. ConvTsetlinMachine.patch_clause_outputs keeps the dense evaluation.
  • No host synchronisation in an update (G18). Labels already on a CUDA device are checked by a device-side assertion (utils.class_targets); labels from the host are checked there before the copy. Feedback selection uses scatter_, the CDF table is cached per device, and the table width comes from the batch size instead of a read-back.
  • CUDA graphs (G19). On CUDA, an update shape seen for the third time (sequential mode: blocks of 64 examples) is captured and replayed. Off with model.cuda_graphs = False or TORCHTSETLIN_CUDA_GRAPHS=0; not used with clause or literal dropout.
  • functional.commit_dense and functional.commit_single_example update include_count in place; commit_dense takes max_events and no longer sums the include counts inside the compiled kernel (half its time). TORCHTSETLIN_TRITON=0 disables the Triton kernels.
  • Start-up: the first update of a process takes 2.2 s cold / 0.7 s warm (was 5.2 / 2.1 s, G23).

0.5.1 (2026-10-28)

Faster GPU training, and two CPU slow paths removed (gaps G10-G14 of the cross-library benchmark). Learning is unchanged in distribution; clause evaluation on CUDA is bit-identical. Times are per update() on an RTX 3090 / Ryzen 9 3950X after warm-up, MNIST-sized models (20k clauses).

  • Fused dense commit on CUDA (G10). A batched GPU update applies its feedback with one torch.compile kernel (functional.commit_dense) that draws the binomials inside the kernel (inverse CDF by bisection over a fixed table), writes the state and the include cache, and zeroes the counts for reuse, instead of ~20 full passes over the automata. Flat MNIST: batch 32 7.2 -> 3.9 ms, batch 100 7.6 -> 4.1 ms. Hard budgets and counts above 255 per automaton keep the eager commit.
  • Clauses are evaluated in float16 on CUDA (G11). The include cache is float16 on CUDA (tensor-core matmul). The evaluation only tests whether a count of violated literals is zero, which half precision decides exactly, so clause outputs, votes and every random draw are unchanged. compute_dtype still sets the literals and the feedback counts; the CPU keeps it.
  • Convolutional batches are no longer split into tiny chunks (G12). The chunk size counted the worst-case random-patch draw (every clause selected for every example), which split a batch of 16 MNIST images into 4 chunks. It now follows the largest real intermediate, the (P, C) evaluation block, and the patch draw is bounded separately by blocks of events (_event_block). With G10/G11, conv MNIST batch 16: 9.6 -> 4.1 ms on CUDA.
  • Sequential mode on CUDA: small models and convolutional models use the fused kernel (G13). Whether to compile is decided on the work of the whole update() call, not one step, and ConvTsetlinMachine records each example's per-clause random matching patch for functional.commit_single_example, which now accepts (C, 2F) literals (and literals_ii). Noisy XOR: 3.1 -> 0.55 ms per example; 2-D Noisy XOR (conv): 3.6 -> 0.73 ms.
  • CPU: two slow paths removed (G14). Clause-major evaluation is used only for up to 256 rows: for the thousands of patch rows of a convolutional batch it was 3x slower (conv MNIST batch 16, 16 threads: 619 -> 258 ms per update). Counts beyond the CPU kernels' 64 x 32 table (large batches, small s) now bisect the wide table instead of falling back to the eager geometric sampler (coalesced MNIST, 2000 clauses, s=3, batch 100: 2047 -> 110 ms).

0.5.0 (2026-10-24)

Learning follows the reference implementations, and training is much faster. A configuration audit against pyTsetlinMachine, pyTsetlinMachineParallel, PyTsetlinMachineCUDA, tmu and green-tsetlin found nine gaps; eight are closed here, and CPU training is the one still open (14x faster, but still slower than pyTsetlinMachine on one core). G1, G3 and G4 change what a model learns, so results measured with 0.4.0 on weighted, regression or focused-sampling models are not directly comparable.

  • Behaviour change: clause weights floor at 1, not 0 (G1). TsetlinMachine(weighted=True) and RegressionTsetlinMachine(weighted=True) used to let Type II drive a weight to 0, which silences the clause. pyTsetlinMachine and tmu keep every weight at least 1.
  • Behaviour change: regression feedback probability is the squared error (G3), ((v* - v)/T)**2, as in pyTsetlinMachine, pyTsetlinMachineParallel and tmu. It was |v* - v|/T.
  • Behaviour change: focused negative sampling uses the reference rule (G4). A non-target class is drawn with probability proportional to (T + clip(v_k, -T, T)) / 2T, as in tmu and green-tsetlin. It was proportional to v_k - min(v) + 1. functional.sample_negative_classes takes a new T argument and raises without it when focused=True.
  • Behaviour change: automaton states are 8-bit by default (G6). state_dtype=None picks uint8 when 2 * n_states - 1 <= 255 (the default n_states=128), else int16 / int32, so a model and its checkpoint are 4x smaller, the same 8 bits per automaton the reference implementations use. Commits form the new state in a wider buffer, so narrow dtypes cannot wrap. Checkpoints saved with int32 states load unchanged. Cast before doing arithmetic on ta_state yourself (model.ta_state.long() - N).
  • Faster CPU training and sequential mode (G8, G9). On the CPU and in sequential mode the commit is row-sparse (functional.apply_feedback_rows): Type Ia / Type II counts are kept only for the clauses that matched and were selected, Type Ib forgetting is drawn by geometric gaps (functional.sample_forget_events, exact), and the include caches are refreshed only where the state changed. The count buffers are reused between updates. Same distribution as before. MNIST-sized model (20k clauses, batch 32): CPU 2.2x faster with 16 threads (and it now scales with threads, 2.7x from 1 to 16), GPU sequential mode 2.8x faster. Batched GPU training keeps the dense commit and is unchanged.
  • torch.compile kernels for the update (G8, G9). On the CPU, Type Ib forgetting and the binomial draws of the row-sparse commit run as exact inverse-CDF kernels with the random numbers drawn inside the kernel, and clause evaluation is computed clause-major. In sequential mode on CUDA, flat models (TsetlinMachine, CoalescedTsetlinMachine, RegressionTsetlinMachine) commit each example with one fused kernel (functional.commit_single_example). MNIST-sized model, one epoch from initialisation: CPU batch 32 with 16 threads 1,259 s -> 91 s, GPU sequential mode 406 s -> 36 s (including compilation). The compiled paths are used only for large enough work, never with an explicit generator=, and fall back to the eager code (with one warning) where torch.compile does not work. functional.set_compile(False) or TORCHTSETLIN_COMPILE=0 turns them off. Compiled and eager runs consume random numbers differently, so a seeded run reproduces only under the same setting. The first update of a session pays the compilation (seconds; cached on disk).
  • max_weight caps clause weights (G2): TsetlinMachine, RegressionTsetlinMachine and (on the magnitude) CoalescedTsetlinMachine.
  • clamp_prediction_votes is now a constructor argument (G7), for pyTsetlinMachine's clamped argmax.
  • Documented (G5): a clause over the literal budget still gets its weight updated, as in tmu; pyTsetlinMachine skips that increment.

0.4.0 (2026-10-22)

Training now matches the reference implementation (tmu) on the TM Composites benchmark. Reproducing TMComposites (Granmo, 2023) on CIFAR-10 turned up two library gaps. Both are fixed here. With 0.4.0, torchtsetlin reproduces 8 of the 9 rows of the paper's Table 2, against 1 of 9 with 0.3.2 (the maintainers' experiment records). Two behaviour changes, so check results you compare against 0.3.x:

  • Behaviour change: the clause budget is soft again by default (budget_mode="soft", MC-2). max_included_literals now follows the reference implementation (tmu): the budget only gates Type Ia, so a clause may overshoot it and is then pruned by Type Ib until it shrinks back.
  • Why: the 0.3.x hard cap reverted every inclusion beyond the budget, so no clause ever exceeded it and the Type Ia -> Type Ib switch never fired. Clauses froze at exactly the budget.
  • Effect on the TM Composites CIFAR-10 reproduction (batch 50, 3 seeds): the 3x3 / 4x4 colour-thermometer specialists go from about 51% to 61.5-61.7%, matching tmu. The four-specialist composite goes from 68.6% to 73.3%.
  • Compatibility: budget_mode="hard" restores 0.3.x. Every model trained with max_included_literals learns differently, so results measured with 0.3.x and a budget are not directly comparable. Experiments that recorded results under 0.3.x pass no budget_mode, so re-running them now uses the soft rule.
  • Classifier predictions no longer clamp vote sums (MC-1). Learning still clamps each class sum to [-T, T], because the feedback probability is defined on it. forward() and predict() used the clamped sum too, so every class that reached +T tied for the argmax, and ties went to the lowest class index. forward() now returns the raw class sums, as the reference implementations do.
  • Measured on the TM Composites CIFAR-10 specialists, the clamp had cost 0.6-3.9 pp of test accuracy.
  • predict_proba() and confidence() still clamp, so the probabilities they return are unchanged.
  • RegressionTsetlinMachine keeps the clamp (new class attribute clamp_prediction_votes = True), because its output is the clamped sum rescaled to the target range.
  • This is a behaviour change: a classifier whose class sums exceed T predicts differently from 0.3.2, almost always better.

0.3.2 (2026-10-19)

A segmentation memory fix, and documentation for the Tsetlin-machine literature. There are no API changes, and every non-segmentation model behaves exactly as in 0.3.1.

  • Segmentation: committed updates are budgeted per commit window (LG-001). With patches_per_commit set, the chunk budget now counts only the (P, 2L) literals per image plus one commit window, rather than every intermediate per image. Before, 128-px images with a few hundred clauses were processed one image per chunk, so a commit could never mix pixels from different images. forward() and patches_per_commit=None keep the per-image bound.
  • Segmentation: opt-in pixel_order="shuffle" permutes a chunk's pixels before committing. Returned votes stay in row-major (image, patch) order. The default is unchanged.
  • Docs: new Benchmarks → Literature results page. It lists every dataset and reported result from 55 Tsetlin-machine papers (128 datasets, 3,295 numbers). Filtering, grouping and best-per-group ranking run as SQL in the browser over a SQLite catalog. The page also has a best-per-dataset leaderboard, dataset and paper tables, and a SQL console. The catalog's source of truth is benchmarks/literature/papers/*.json, rebuilt by benchmarks/literature/build_catalog.py.
  • Docs: the changelog page renders again; it was missing the pymdownx.snippets extension. The site now uses the white paper's orange palette, with an automata-grid logo and favicon (scripts/make_logo.py). The concept figures are recoloured to match, and the current release is shown site-wide.

0.3.1 (2026-10-12)

3D convolution. Clauses can now slide through volumes: MRI/CT stacks, or frame sequences with time as depth.

  • New models: Conv3dTsetlinMachine, Conv3dCoalescedTsetlinMachine and Conv3dRegressionTsetlinMachine take (B, Z, D, H, W) Boolean volumes with a kd × kh × kw window and depth/row/column thermometer position literals. Clause evaluation and the random-matching-patch feedback are the 2D code, unchanged. With D = kd = 1, the literals and the whole training run are bit-identical to ConvTsetlinMachine.
  • Patch-axis blocking: when one volume would exceed max_chunk_elements, the patch axis is split into blocks (or set patches_per_chunk). The output is identical, and the patch draw has the same distribution.
  • clause_patch returns (Z, kd, kh, kw), clause_region adds a "d" range, and patch_clause_outputs returns (B, Pd, Ph, Pw, C). viz.plot_conv_clause(s) draws 3D clauses slice by slice and takes depth= to show one slice.
  • data.make_3d_shapes: two shapes that differ only in the order of their slices. examples/shapes_conv3d.py gets 1.000 on it, against 0.83–0.98 for the 2D model on slices stacked as channels and 0.73–0.80 for a flat machine.
  • Docs: a "3D volumes" section with two new figures in Convolution, a conv3d benchmark suite on the CPU-vs-GPU page, and the design and proofs in torchtsetlin_plans/plans/conv3d.md.

0.3.0 (2026-10-01)

The clause-size budget is now a hard limit. This is a behaviour change: models trained with max_included_literals will learn differently from 0.2.0.

  • max_included_literals caps clause growth in every feedback mode (issue #1). Before, the budget was only checked at the start of a commit. One batched commit aggregates many Type Ia and Type II events, and Type II was never gated, so a clause under budget could end the commit far over it: 41% of rules exceeded a budget of 6, and segmentation models averaged about 200 literals against a budget of 32. Now, after each commit, a clause that would exceed the budget keeps only a random subset of its newly included literals and the rest return to just below the include boundary. Oversized clauses still get forgetting-only feedback and can only shrink. Results measured with a budget under 0.2.0 are not directly comparable.
  • Fixed: SegmentationTsetlinMachine crashed on GPU when class_feedback_p was set before .to(device) (issue #1). It is now a non-persistent buffer, so it moves with the model; checkpoints are unchanged and 0.2.0 checkpoints still load.

0.2.0 (2026-09-23)

Semantic segmentation. Dense, per-pixel prediction is now a supported task rather than something to rebuild in a notebook.

  • New models: SegmentationTsetlinMachine and CoalescedSegmentationTsetlinMachine (models/segmentation.py). A convolutional TM takes the disjunction over patch positions — matches.any(dim=1) — which gives it translation tolerance and makes a dense output impossible: afterwards it knows a pattern occurred, not where. The dense models keep the patch axis and fold it into the batch axis instead (B' = B·P), so vote sums, Type I / Type II selection, feedback counting and apply_feedback all apply unchanged. predict returns a (B, H, W) label map, vote_map a (B, K, H, W) vote surface, and forward the folded (B·P, K) votes that keep Trainer / metrics / interpret working. padding="same" with stride=1 preserves the input resolution; ignore_index handles the void class of CamVid / Cityscapes / VOC; multi-label mode takes (B, K, H, W) mask stacks.
  • patches_per_commit (default 128). One batch of 8 images at 32×32 is 8 192 pixel-examples, and committing their feedback at once is a mini-batch of 8 192 — far past where batched feedback stops matching the classical algorithm. Measured over 3 seeds on make_segmentation_shapes: mIoU 0.749 at 128 against 0.527 at 4 096, and the variance grows with the commit size too (sd 0.009 → 0.073), so a large-commit run can look fine once and collapse the next time. feedback_mode="sequential" is patches_per_commit=1.
  • Context, measured. A k × k patch cannot decide classes that need global structure. Two TM-native fixes ship: thermometer-encoded patch-position literals (position_encoding, now also an int to bound the feature count on large images) and data.PyramidEncoder, an OR-pooled multi-scale stack built on the new functional.boolean_pool and functional.thermometer_cast. On generated CamVid-like scenes, building IoU goes 0.505 with neither → 0.699 (pyramid) → 0.894 (position) → 0.921 (both), and mIoU 0.798 → 0.959. No float parameter and no gradient anywhere.
  • Imbalance: class_feedback_p plus data.balanced_class_probabilities. A Tsetlin machine has no loss to reweight, so the lever is which pixels produce feedback. It is a rescue, not a default — it lifts a pyramid-only run 0.874 → 0.927 mIoU but costs 0.05 once position literals are on.
  • Metrics: pixel_accuracy, iou, mean_iou, dice, boundary_f1, segmentation_confusion_matrix, segmentation_metrics and segmentation_report, all accepting vote maps, label maps or folded votes. Absent classes get NaN IoU rather than 0, and mean_iou skips them. confusion_matrix gained ignore_index.
  • Trainer detects a dense model, logs pixel accuracy / mIoU / mean Dice / per-class IoU, and accumulates the confusion matrix batch by batch instead of keeping (B, K, H, W) vote tensors for a whole test set.
  • Interpretability: interpret.explain_pixel lists the clauses that decided one pixel, decoded over absolute image coordinates (p[1,21,13] = "plane 1 of pixel (21, 13)"), so a dense prediction can be audited pixel by pixel rather than attributed by a saliency heuristic. Plus model.clause_map, model.pixel_feature_names, clause_patch and clause_region for the dense geometry.
  • Data: make_scenes (CamVid-like street scenes with a wavy horizon, per-class texture and CamVid-like class imbalance), make_segmentation_shapes (a fast toy where the classes are only separable from the neighbourhood), load_segmentation_boolean and load_voc_segmentation_boolean — the latter resize masks with nearest interpolation, since bilinear invents class indices that do not exist.
  • Visualisation: viz.plot_segmentation (image / truth / prediction / error panels) and viz.plot_vote_map, plus viz.segmentation_palette.
  • _ConvMixin.patch_clause_outputs exposes the per-patch match tensor (B, Py, Px, C) that previously had no public accessor — useful for plotting where a clause fires and for stacking blocks, though learning a dense output still needs the segmentation models.
  • Benchmarks: a segmentation suite in bench_device.py reporting pixels per second, with a figure, table and page section. Measured on a 16-core CPU: ~35 000 px/s training and ~1 090 000 px/s predicting at the default commit size; patches_per_commit=None is 4.2× faster and measurably worse.
  • Docs: new concepts/segmentation.md, guides/segmentation.md and examples/segmentation.md, with every number above reproduced from examples/segmentation_scenes.py. They also report the row-prior baseline — a classifier that sees no image content and still scores 0.876 pixel accuracy on these scenes — because pixel accuracy on a layout-driven dataset is a weak claim.
  • Internal: TsetlinMachineBase._accumulate_chunk split into _accumulate_literals so models that encode once and commit several times do not re-encode. No behaviour change.

0.1.3 (2026-09-15)

  • Fixed / faster (convolutional models): the random matching patch used for Recognize and Reject feedback was drawn in _ConvMixin._evaluate, which builds a (B, P, C) rand tensor on every call — including forward() / predict() / evaluate_clauses(), where the draw is discarded. _evaluate now returns the per-patch match tensor as its feedback context and _feedback_counts draws from it, over the selected feedback events only. Prediction is RNG-free: on a 400-clause 10x10-window MNIST config, predict() went 885 -> 180 ms and update() 914 -> 216 ms per 64 images (4.9x / 4.2x). Each feedback event now also draws its own patch; a ConvCoalescedTsetlinMachine clause that takes Type Ia and Type II in the same update (16% of feedback pairs in a 4-output probe, 43% multi-label) was sharing one. Learning is unchanged for ConvTsetlinMachine, where the two feedback types never coincide.
  • Verified the convolutional implementation against chapter 4 of An Introduction to Tsetlin Machines — patch layout, the OR over patches, the thermometer position bits (P-1 per axis, bit k = coord >= k+1) and Recognize / Erase / Reject feedback all match the theory. Three new tests pin those semantics against a brute-force reference.
  • Examples: three new convolutional scripts — examples/shapes_conv.py (2-D clauses vs a flat machine, and what position_encoding costs on a translation-invariant task), examples/conv1d_ramps.py (Conv1dTsetlinMachine on thermometer-encoded signals) and examples/conv_regression_blobs.py (ConvRegressionTsetlinMachine). examples/mnist_conv.py gained --stride, --no-position-encoding, --coalesced and --max-samples, keeps the encoder on the compute device, and prints the clauses it learned. New examples/README.md indexes all of them.
  • Docs: new Convolution on generated data example page (docs/examples/convolution.md) in the Examples nav, a runnable-examples table on the Convolution concept page, and measured --stride / --coalesced / position_encoding comparisons on the MNIST example page.

0.1.2 (2026-09-15)

  • Fixed (silent data corruption on GPU): as_bool_tensor / as_long_tensor / as_float_tensor moved tensors with non_blocking=True regardless of direction. A device-to-host copy issued that way returns before the transfer completes, so a CPU-resident BooleanEncoder handed a CUDA tensor thresholded stale memory and returned roughly 40% wrong bits — with no error, just a quietly worse model. All three now route through utils._to_device, which uses non_blocking=True only when the destination is CUDA; Trainer used the same pattern and is fixed too.
  • Added: two notebooks working through the Tsetlin-machine segmentation literature — examples/notebooks/04_convolutional_regression_tsetlin.ipynb (C-RTM, ICMLT 2021) and examples/notebooks/05_ctm_unet_segmentation.ipynb (CTM-UNet, ISTM 2025), the latter including a dense per-pixel Tsetlin segmentation head built on TsetlinMachine.

0.1.1 (2026-09-14)

  • Fixed: the 0.1.0 wheel on PyPI was missing the torchtsetlin.data subpackage (it had been excluded from git by an over-broad .gitignore rule), which made import torchtsetlin fail. 0.1.0 should not be used.
  • The publish workflow now runs the test-suite and smoke-imports the built wheel before uploading.

0.1.0 (2026-09-14)

First public release.

  • Models: TsetlinMachine (multi-class, optional integer clause weights), CoalescedTsetlinMachine (shared clauses, multi-class / multi-label), RegressionTsetlinMachine, convolutional variants (ConvTsetlinMachine, ConvCoalescedTsetlinMachine, ConvRegressionTsetlinMachine, Conv1dTsetlinMachine).
  • Learning options: specificity s, vote margin T, memory depth n_states, boosted true-positive feedback, clause size constraint (max_included_literals), drop-clause and drop-literal regularisation, focused negative sampling, batched or exact sequential feedback.
  • Data preparation: thermometer / one-hot / bit-plane / adaptive-threshold / colour thermometer / hypervector encoders, synthetic datasets, torchvision helpers.
  • Training: Trainer with DataLoader support, callbacks (early stopping, checkpoints, CSV logging, hyper-parameter schedules), metrics.
  • Interpretation: rule extraction, clause activity/precision, closed-form global and local feature importance, per-example explanations.
  • Visualisation: memory plots, automata heat-maps, convolutional clause patches, confusion matrices, trustworthiness curves.
  • Documentation site (MkDocs) and examples.