Fuzzy clauses¶
An ordinary clause is an AND: one included literal that is False switches the clause off. On images this forces a trade. A clause with many literals describes a pattern well but almost never matches a new image; a clause with few literals matches often but says little. The usual answer is to use thousands of clauses.
The Fuzzy-Pattern Tsetlin machine (Hnilov, arXiv:2508.08350;
implemented in Tsetlin.jl) changes the clause instead.
FuzzyTsetlinMachine is that algorithm for flat inputs.
The clause output¶
A fuzzy clause counts how many of its included literals are False for the input and votes
| Included literals that fail | Ordinary clause | Fuzzy clause, max_failed_literals=8 |
|---|---|---|
| 0 | 1 | 8 |
| 1 | 0 | 7 |
| 5 | 0 | 3 |
| 8 or more | 0 | 0 |
A clause matches when its output is above 0. A long clause therefore still votes for an
input that resembles its pattern, with a weight that says how well it fits. With
max_failed_literals=1 the output is the ordinary 0/1 value.
The class sum is the sum of the outputs of the positive clauses minus that of the negative
ones, so it can reach n_clauses / 2 * max_failed_literals. T is compared with that sum.
The feedback¶
The feedback rules are changed to fit a clause that tolerates failures.
| Feedback | Ordinary machine | Fuzzy machine |
|---|---|---|
| Type I, matching clause, True literal | one step towards inclusion | the same, with probability 1 |
| Type I, matching clause, False literal | one step towards exclusion with probability 1/s |
one step towards exclusion with probability 1 if the literal is excluded; included False literals are not touched |
| Type I, clause that does not match | every literal: towards exclusion with probability 1/s |
the same |
| Type II, matching clause | excluded False literals: one step towards inclusion | the same |
| Classes that learn from an example | the target class and one drawn other class | the target class and every other class (negative_classes="all") |
Two consequences are worth knowing:
shas one job. It is only used to forget in clauses that do not match, so useful values are much larger than for the ordinary machine: 200 to 2 000 instead of 4 to 10.- Clauses grow fast. Type I on a matching clause is deterministic, so a clause collects
literals quickly.
max_included_literalslimits that.
The literal limit is a gate¶
In the other models max_included_literals turns Type I feedback into forgetting once a clause
is over the budget. Here it is a gate: a matching clause that includes that many literals or
more gets no steps towards inclusion. Nothing is reverted and nothing is forgotten because
of the limit. In the experiment that preceded the model, the ordinary budget rule cost 27 to
36 percentage points at the settings below.
Settings that work¶
The settings of Tsetlin.jl's MNIST example carry over (the include limit is the midpoint of
2 * n_states = 256 states, the default):
| Clauses per class | T |
s |
max_failed_literals |
max_included_literals |
|---|---|---|---|---|
| 20 | 16 | 800 | 75 | 150 |
| 200 | 28 | 200 | 8 | 16 |
| 2 000 | 64 | 400 | 4 | 12 |
import torchtsetlin as tt
model = tt.FuzzyTsetlinMachine(784, 10, n_clauses=20, T=16, s=800,
max_failed_literals=75, max_included_literals=150)
votes = model.update(x, y) # one learning step on a batch
pred = model.predict(x)
Few clauses want many literals and a large tolerance; many clauses want short, strict ones.
What it buys¶
Flat Booleanized input, 100 epochs, batch 50, one seed, test accuracy at the last epoch (the maintainers' experiment records):
| Dataset | Fuzzy, 20 clauses per class | Fuzzy, 200 clauses per class | Ordinary, 2 000 clauses per class |
|---|---|---|---|
| MNIST | 97.53 % | 98.41 % | 97.55 % |
| Fashion-MNIST | 88.08 % | 89.31 % | 88.80 % |
The ordinary machine is at its best known setting in that harness. These numbers come from one seed and two datasets; treat the size of the gap as indicative.
Batches¶
Mini-batches work as for the other models: every event of a batch is computed from the automata at its start, the events are summed and applied once (batched vs sequential feedback). The fuzzy rules are robust to this: batch sizes from 10 to 1 000 stayed within 0.6 percentage points of the sequential algorithm on MNIST and Fashion-MNIST.
On CUDA the update is plain tensor code without host synchronisation, so it is captured and
replayed as a CUDA graph (models up to dense_commit_max_elements automata; larger ones and
models with dropout update only the clauses that received feedback). On the CPU, clauses that
only forget are updated by a sparse draw.
Reading the clauses¶
A fuzzy clause is not a strict conjunction, and the rules say so:
model.rules()[0]
# 'IF fewer than 8 of (x12, x40, NOT x77, ...) fail THEN 3'
model.explain_clause(x[0], clause=5)
# {'clause': 5, 'class': 0, 'polarity': 1, 'satisfied': [...], 'failed': [...],
# 'output': 6, 'vote': 6}
explain_clause lists, for one input, which included literals hold and which fail, and the
clause's vote. torchtsetlin.interpret.explain works as for the other models; the weight of a
matched clause is its fuzzy output.
Limits¶
- Flat inputs and multi-class classification only: no convolutional, regression, coalesced or segmentation variant yet.
- No clause weights (
weighted=Trueis rejected). - Empty clauses follow the library rule (they vote while learning, not when predicting); Tsetlin.jl lets them vote in both cases. The difference was not measurable.