Skip to main content

tsetly

A tiny Tsetlin Machine in NumPy: little automata that learn rules you can read.

      forget ◀────────────────┼────────────────▶ remember
             1   2   3  …  N  │  N+1  …  2N

A Tsetlin Machine learns AND-rules over bits, like x0 ∧ ¬x1. Every rule is a team of Tsetlin automata, one per bit and one per negated bit. Each automaton walks along its states as the data rewards or penalises it, and once it crosses the middle, its bit joins the rule. Rules vote for or against each class, and the class with the most votes wins. That is the whole machine (Granmo, 2018).

Install

pip install tsetly

Learn XOR through noise

Twelve random bits, of which only the first two matter, and a fifth of the training labels flipped:

import numpy as np
from tsetly import TsetlinMachine

rng = np.random.default_rng(0)
X = rng.integers(0, 2, size=(5000, 12))
y = X[:, 0] ^ X[:, 1]
noisy = np.where(rng.random(5000) < 0.2, 1 - y, y)

tm = TsetlinMachine(clauses=8, T=15, s=3.9, seed=1)
tm.fit(X[:4000], noisy[:4000], epochs=20)

print(tm.score(X[4000:], y[4000:]))  # 1.0
print(tm)
class 0
   +2  ¬x0 ∧ ¬x1
   +2  x0 ∧ x1
   -2  x0 ∧ ¬x1
   -2  ¬x0 ∧ x1
class 1
   +3  ¬x0 ∧ x1
   +1  x0 ∧ ¬x1
   -3  ¬x0 ∧ ¬x1
   -1  x0 ∧ x1

It found XOR, ignored the ten distracting bits, and can tell you so.

API

TsetlinMachine(clauses=20, T=15, s=3.9, states=100, seed=None) clauses per class (half vote for, half against), the vote target T, the specificity s, the states per action
fit(X, y, epochs=10) learn from bits X (samples × features, 0/1) and labels y of any kind
predict(X) the class with the most votes
votes(X) every class's vote total, samples × classes
score(X, y) accuracy
rules(label, names=None) a class's rules and their votes, optionally with your feature names
print(tm) every rule the machine learned

License

MIT

Metadata

Release files for tsetly 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tsetly 0.0.1
File Size Uploaded Provenance Actions
tsetly-0.0.1.tar.gz 6.2 kB Without provenance Details for tsetly-0.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tsetly 0.0.1
File Interpreter ABI Platform Actions
tsetly-0.0.1-py3-none-any.whl Python 3 none any Details for tsetly-0.0.1-py3-none-any.whl

Total release size: 12.8 kB

Release files / tsetly-0.0.1.tar.gz

Download URL tsetly-0.0.1.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
137183a79e71b7a61eb58d2df6c7e59a07b1f2473c475b975eab4894ec9eae1a
BLAKE2b-256 checksum
How to use checksums
cbbf711cade4d051382fceda6d195af40f4f4c3100dda083b4bd71bf4533d859
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / tsetly-0.0.1-py3-none-any.whl

Download URL tsetly-0.0.1-py3-none-any.whl
Size 6.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6cb46ec2939922ca5d1d598ce8606221e7f8b564d7d4af19dff19f59d0ac7165
BLAKE2b-256 checksum
How to use checksums
931652443acd2f631ccde1e697dc9247f124e161290d42f8832d4059e6013e04
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for tsetly 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page