torchtsetlin 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- torchtsetlin-0.1.0/LICENSE +21 -0
- torchtsetlin-0.1.0/PKG-INFO +149 -0
- torchtsetlin-0.1.0/README.md +100 -0
- torchtsetlin-0.1.0/pyproject.toml +83 -0
- torchtsetlin-0.1.0/setup.cfg +4 -0
- torchtsetlin-0.1.0/src/torchtsetlin/__init__.py +73 -0
- torchtsetlin-0.1.0/src/torchtsetlin/functional.py +284 -0
- torchtsetlin-0.1.0/src/torchtsetlin/interpret.py +198 -0
- torchtsetlin-0.1.0/src/torchtsetlin/metrics.py +143 -0
- torchtsetlin-0.1.0/src/torchtsetlin/models/__init__.py +24 -0
- torchtsetlin-0.1.0/src/torchtsetlin/models/base.py +501 -0
- torchtsetlin-0.1.0/src/torchtsetlin/models/classifier.py +236 -0
- torchtsetlin-0.1.0/src/torchtsetlin/models/coalesced.py +213 -0
- torchtsetlin-0.1.0/src/torchtsetlin/models/conv.py +360 -0
- torchtsetlin-0.1.0/src/torchtsetlin/models/regression.py +151 -0
- torchtsetlin-0.1.0/src/torchtsetlin/py.typed +0 -0
- torchtsetlin-0.1.0/src/torchtsetlin/train/__init__.py +29 -0
- torchtsetlin-0.1.0/src/torchtsetlin/train/callbacks.py +198 -0
- torchtsetlin-0.1.0/src/torchtsetlin/train/history.py +55 -0
- torchtsetlin-0.1.0/src/torchtsetlin/train/trainer.py +266 -0
- torchtsetlin-0.1.0/src/torchtsetlin/utils.py +98 -0
- torchtsetlin-0.1.0/src/torchtsetlin/viz.py +228 -0
- torchtsetlin-0.1.0/src/torchtsetlin.egg-info/PKG-INFO +149 -0
- torchtsetlin-0.1.0/src/torchtsetlin.egg-info/SOURCES.txt +28 -0
- torchtsetlin-0.1.0/src/torchtsetlin.egg-info/dependency_links.txt +1 -0
- torchtsetlin-0.1.0/src/torchtsetlin.egg-info/requires.txt +30 -0
- torchtsetlin-0.1.0/src/torchtsetlin.egg-info/top_level.txt +1 -0
- torchtsetlin-0.1.0/tests/test_data_train.py +208 -0
- torchtsetlin-0.1.0/tests/test_functional.py +112 -0
- torchtsetlin-0.1.0/tests/test_models.py +241 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Vajira Thambawita
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: torchtsetlin
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: GPU-enabled, PyTorch-native Tsetlin Machine framework: models, data preparation, training, evaluation, interpretation and visualization.
|
|
5
|
+
Author-email: Vajira Thambawita <vajira@simula.no>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/vlbthambawita/torchtsetlin
|
|
8
|
+
Project-URL: Documentation, https://vlbthambawita.github.io/torchtsetlin/
|
|
9
|
+
Project-URL: Repository, https://github.com/vlbthambawita/torchtsetlin
|
|
10
|
+
Project-URL: Issues, https://github.com/vlbthambawita/torchtsetlin/issues
|
|
11
|
+
Keywords: tsetlin machine,pytorch,interpretable machine learning,logic-based learning,gpu
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
21
|
+
Requires-Python: >=3.9
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: torch>=2.0
|
|
25
|
+
Requires-Dist: numpy>=1.22
|
|
26
|
+
Provides-Extra: viz
|
|
27
|
+
Requires-Dist: matplotlib>=3.5; extra == "viz"
|
|
28
|
+
Provides-Extra: vision
|
|
29
|
+
Requires-Dist: torchvision>=0.15; extra == "vision"
|
|
30
|
+
Provides-Extra: sklearn
|
|
31
|
+
Requires-Dist: scikit-learn>=1.1; extra == "sklearn"
|
|
32
|
+
Provides-Extra: docs
|
|
33
|
+
Requires-Dist: mkdocs>=1.5; extra == "docs"
|
|
34
|
+
Requires-Dist: mkdocs-material>=9.4; extra == "docs"
|
|
35
|
+
Requires-Dist: mkdocstrings[python]>=0.24; extra == "docs"
|
|
36
|
+
Requires-Dist: mkdocs-autorefs>=0.5; extra == "docs"
|
|
37
|
+
Provides-Extra: dev
|
|
38
|
+
Requires-Dist: pytest>=7; extra == "dev"
|
|
39
|
+
Requires-Dist: pytest-timeout; extra == "dev"
|
|
40
|
+
Requires-Dist: matplotlib>=3.5; extra == "dev"
|
|
41
|
+
Requires-Dist: scikit-learn>=1.1; extra == "dev"
|
|
42
|
+
Requires-Dist: torchvision>=0.15; extra == "dev"
|
|
43
|
+
Requires-Dist: ruff; extra == "dev"
|
|
44
|
+
Requires-Dist: build; extra == "dev"
|
|
45
|
+
Requires-Dist: twine; extra == "dev"
|
|
46
|
+
Provides-Extra: all
|
|
47
|
+
Requires-Dist: torchtsetlin[dev,docs,sklearn,vision,viz]; extra == "all"
|
|
48
|
+
Dynamic: license-file
|
|
49
|
+
|
|
50
|
+
# torchtsetlin
|
|
51
|
+
|
|
52
|
+
**GPU-enabled, PyTorch-native Tsetlin machines** — models, data preparation, training,
|
|
53
|
+
evaluation, interpretation and visualisation in one package.
|
|
54
|
+
|
|
55
|
+
[](https://github.com/vlbthambawita/torchtsetlin/actions)
|
|
56
|
+
[](https://vlbthambawita.github.io/torchtsetlin/)
|
|
57
|
+
[](LICENSE)
|
|
58
|
+
|
|
59
|
+
A [Tsetlin machine](https://tsetlinmachine.org) learns propositional rules
|
|
60
|
+
(`IF x0 AND NOT x1 THEN class 1`) with teams of learning automata instead of gradients.
|
|
61
|
+
`torchtsetlin` implements the family as ordinary `torch.nn.Module`s: the automata live in
|
|
62
|
+
tensors, so a model moves between CPU and GPU with `.to(device)`, is saved with
|
|
63
|
+
`state_dict()`, and learns from mini-batches with a single `model.update(x, y)` call.
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
import torchtsetlin as tt
|
|
67
|
+
|
|
68
|
+
x_train, y_train = tt.data.make_noisy_xor(5000, noise=0.4) # Boolean features, int labels
|
|
69
|
+
x_test, y_test = tt.data.make_noisy_xor(2000, noise=0.0, seed=1)
|
|
70
|
+
|
|
71
|
+
model = tt.TsetlinMachine(n_features=12, n_classes=2, n_clauses=20, T=15, s=3.9).to("cuda")
|
|
72
|
+
|
|
73
|
+
# PyTorch-style loop: update() is the analogue of loss.backward(); optimizer.step()
|
|
74
|
+
for epoch in range(50):
|
|
75
|
+
model.train()
|
|
76
|
+
for i in range(0, 5000, 10):
|
|
77
|
+
model.update(x_train[i:i+10].cuda(), y_train[i:i+10].cuda())
|
|
78
|
+
model.eval()
|
|
79
|
+
acc = (model(x_test.cuda()).argmax(1) == y_test.cuda()).float().mean()
|
|
80
|
+
|
|
81
|
+
print(model.rules()[:2]) # ['IF x0 AND NOT x1 THEN 1', 'IF x1 AND NOT x0 THEN 1']
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Or with the built-in trainer:
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
trainer = tt.Trainer(model, batch_size=10, callbacks=[tt.EarlyStopping(patience=20)])
|
|
88
|
+
trainer.fit((x_train, y_train), epochs=100, val_data=(x_test, y_test))
|
|
89
|
+
trainer.evaluate((x_test, y_test)) # {'accuracy': 0.99}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Features
|
|
93
|
+
|
|
94
|
+
| | |
|
|
95
|
+
|---|---|
|
|
96
|
+
| **Models** | `TsetlinMachine` (multi-class, optional integer clause weights), `CoalescedTsetlinMachine` (shared clauses; multi-class or multi-label), `RegressionTsetlinMachine`, `ConvTsetlinMachine` / `Conv1dTsetlinMachine` and convolutional coalesced / regression variants |
|
|
97
|
+
| **Learning** | vote margin `T`, specificity `s`, memory depth, boosted true-positive feedback, clause-size constraint, drop-clause / drop-literal, focused negative sampling, **batched** (GPU-friendly) or **exact sequential** feedback |
|
|
98
|
+
| **Data** | thermometer, one-hot, bit-plane, adaptive-threshold, colour-thermometer and hypervector encoders; synthetic datasets; torchvision helpers |
|
|
99
|
+
| **Training** | `Trainer` for tensors / `Dataset` / `DataLoader`, callbacks (early stopping, checkpoints, CSV logs, hyper-parameter schedules), `History` |
|
|
100
|
+
| **Evaluation** | accuracy, confusion matrix, precision/recall/F1, regression and multi-label metrics, calibration, trustworthiness curves |
|
|
101
|
+
| **Interpretation** | rule extraction, clause activity/precision, closed-form global & local feature importance, per-example explanations |
|
|
102
|
+
| **Visualisation** | memory plots, automata heat-maps, convolutional clause patches, confusion matrices, vote distributions |
|
|
103
|
+
|
|
104
|
+
## Installation
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
pip install torch # pick the CUDA/CPU build from pytorch.org
|
|
108
|
+
pip install torchtsetlin # + optional extras: [viz] [vision] [sklearn] [docs] [all]
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
From source: `pip install -e ".[dev]"`, then `pytest` and `mkdocs serve`.
|
|
112
|
+
|
|
113
|
+
## How learning works (in one paragraph)
|
|
114
|
+
|
|
115
|
+
Each clause is an AND of literals (`x_k` or `NOT x_k`); every (clause, literal) pair has a
|
|
116
|
+
Tsetlin automaton whose integer state decides whether the literal is *included*. For a
|
|
117
|
+
training example, clauses of the true class receive **Type I** feedback (memorise the
|
|
118
|
+
example's True literals, forget the rest) and clauses of a random other class receive
|
|
119
|
+
**Type II** feedback (add a False literal so the clause stops matching), each with a
|
|
120
|
+
probability controlled by the vote margin `T`. `torchtsetlin` evaluates a mini-batch with one
|
|
121
|
+
matrix product, counts the feedback events per (clause, literal) with another, and turns the
|
|
122
|
+
counts into binomial state transitions — the whole update is a handful of tensor ops. See the
|
|
123
|
+
[concept pages](https://vlbthambawita.github.io/torchtsetlin/concepts/tsetlin-machine/) for
|
|
124
|
+
details and references.
|
|
125
|
+
|
|
126
|
+
## Documentation
|
|
127
|
+
|
|
128
|
+
* Getting started, concepts, guides, examples and the full API reference:
|
|
129
|
+
<https://vlbthambawita.github.io/torchtsetlin/> (or `mkdocs serve` locally).
|
|
130
|
+
* Runnable scripts in [`examples/`](examples): Noisy XOR, MNIST (flat and convolutional),
|
|
131
|
+
tabular data with thermometer encoding, regression.
|
|
132
|
+
|
|
133
|
+
## Citation
|
|
134
|
+
|
|
135
|
+
If you use torchtsetlin in research, please cite the Tsetlin machine papers whose algorithms
|
|
136
|
+
you rely on (see the documentation) and this package:
|
|
137
|
+
|
|
138
|
+
```bibtex
|
|
139
|
+
@software{torchtsetlin,
|
|
140
|
+
author = {Thambawita, Vajira},
|
|
141
|
+
title = {torchtsetlin: GPU-enabled, PyTorch-native Tsetlin machines},
|
|
142
|
+
year = {2026},
|
|
143
|
+
url = {https://github.com/vlbthambawita/torchtsetlin}
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## License
|
|
148
|
+
|
|
149
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# torchtsetlin
|
|
2
|
+
|
|
3
|
+
**GPU-enabled, PyTorch-native Tsetlin machines** — models, data preparation, training,
|
|
4
|
+
evaluation, interpretation and visualisation in one package.
|
|
5
|
+
|
|
6
|
+
[](https://github.com/vlbthambawita/torchtsetlin/actions)
|
|
7
|
+
[](https://vlbthambawita.github.io/torchtsetlin/)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+
|
|
10
|
+
A [Tsetlin machine](https://tsetlinmachine.org) learns propositional rules
|
|
11
|
+
(`IF x0 AND NOT x1 THEN class 1`) with teams of learning automata instead of gradients.
|
|
12
|
+
`torchtsetlin` implements the family as ordinary `torch.nn.Module`s: the automata live in
|
|
13
|
+
tensors, so a model moves between CPU and GPU with `.to(device)`, is saved with
|
|
14
|
+
`state_dict()`, and learns from mini-batches with a single `model.update(x, y)` call.
|
|
15
|
+
|
|
16
|
+
```python
|
|
17
|
+
import torchtsetlin as tt
|
|
18
|
+
|
|
19
|
+
x_train, y_train = tt.data.make_noisy_xor(5000, noise=0.4) # Boolean features, int labels
|
|
20
|
+
x_test, y_test = tt.data.make_noisy_xor(2000, noise=0.0, seed=1)
|
|
21
|
+
|
|
22
|
+
model = tt.TsetlinMachine(n_features=12, n_classes=2, n_clauses=20, T=15, s=3.9).to("cuda")
|
|
23
|
+
|
|
24
|
+
# PyTorch-style loop: update() is the analogue of loss.backward(); optimizer.step()
|
|
25
|
+
for epoch in range(50):
|
|
26
|
+
model.train()
|
|
27
|
+
for i in range(0, 5000, 10):
|
|
28
|
+
model.update(x_train[i:i+10].cuda(), y_train[i:i+10].cuda())
|
|
29
|
+
model.eval()
|
|
30
|
+
acc = (model(x_test.cuda()).argmax(1) == y_test.cuda()).float().mean()
|
|
31
|
+
|
|
32
|
+
print(model.rules()[:2]) # ['IF x0 AND NOT x1 THEN 1', 'IF x1 AND NOT x0 THEN 1']
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Or with the built-in trainer:
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
trainer = tt.Trainer(model, batch_size=10, callbacks=[tt.EarlyStopping(patience=20)])
|
|
39
|
+
trainer.fit((x_train, y_train), epochs=100, val_data=(x_test, y_test))
|
|
40
|
+
trainer.evaluate((x_test, y_test)) # {'accuracy': 0.99}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Features
|
|
44
|
+
|
|
45
|
+
| | |
|
|
46
|
+
|---|---|
|
|
47
|
+
| **Models** | `TsetlinMachine` (multi-class, optional integer clause weights), `CoalescedTsetlinMachine` (shared clauses; multi-class or multi-label), `RegressionTsetlinMachine`, `ConvTsetlinMachine` / `Conv1dTsetlinMachine` and convolutional coalesced / regression variants |
|
|
48
|
+
| **Learning** | vote margin `T`, specificity `s`, memory depth, boosted true-positive feedback, clause-size constraint, drop-clause / drop-literal, focused negative sampling, **batched** (GPU-friendly) or **exact sequential** feedback |
|
|
49
|
+
| **Data** | thermometer, one-hot, bit-plane, adaptive-threshold, colour-thermometer and hypervector encoders; synthetic datasets; torchvision helpers |
|
|
50
|
+
| **Training** | `Trainer` for tensors / `Dataset` / `DataLoader`, callbacks (early stopping, checkpoints, CSV logs, hyper-parameter schedules), `History` |
|
|
51
|
+
| **Evaluation** | accuracy, confusion matrix, precision/recall/F1, regression and multi-label metrics, calibration, trustworthiness curves |
|
|
52
|
+
| **Interpretation** | rule extraction, clause activity/precision, closed-form global & local feature importance, per-example explanations |
|
|
53
|
+
| **Visualisation** | memory plots, automata heat-maps, convolutional clause patches, confusion matrices, vote distributions |
|
|
54
|
+
|
|
55
|
+
## Installation
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pip install torch # pick the CUDA/CPU build from pytorch.org
|
|
59
|
+
pip install torchtsetlin # + optional extras: [viz] [vision] [sklearn] [docs] [all]
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
From source: `pip install -e ".[dev]"`, then `pytest` and `mkdocs serve`.
|
|
63
|
+
|
|
64
|
+
## How learning works (in one paragraph)
|
|
65
|
+
|
|
66
|
+
Each clause is an AND of literals (`x_k` or `NOT x_k`); every (clause, literal) pair has a
|
|
67
|
+
Tsetlin automaton whose integer state decides whether the literal is *included*. For a
|
|
68
|
+
training example, clauses of the true class receive **Type I** feedback (memorise the
|
|
69
|
+
example's True literals, forget the rest) and clauses of a random other class receive
|
|
70
|
+
**Type II** feedback (add a False literal so the clause stops matching), each with a
|
|
71
|
+
probability controlled by the vote margin `T`. `torchtsetlin` evaluates a mini-batch with one
|
|
72
|
+
matrix product, counts the feedback events per (clause, literal) with another, and turns the
|
|
73
|
+
counts into binomial state transitions — the whole update is a handful of tensor ops. See the
|
|
74
|
+
[concept pages](https://vlbthambawita.github.io/torchtsetlin/concepts/tsetlin-machine/) for
|
|
75
|
+
details and references.
|
|
76
|
+
|
|
77
|
+
## Documentation
|
|
78
|
+
|
|
79
|
+
* Getting started, concepts, guides, examples and the full API reference:
|
|
80
|
+
<https://vlbthambawita.github.io/torchtsetlin/> (or `mkdocs serve` locally).
|
|
81
|
+
* Runnable scripts in [`examples/`](examples): Noisy XOR, MNIST (flat and convolutional),
|
|
82
|
+
tabular data with thermometer encoding, regression.
|
|
83
|
+
|
|
84
|
+
## Citation
|
|
85
|
+
|
|
86
|
+
If you use torchtsetlin in research, please cite the Tsetlin machine papers whose algorithms
|
|
87
|
+
you rely on (see the documentation) and this package:
|
|
88
|
+
|
|
89
|
+
```bibtex
|
|
90
|
+
@software{torchtsetlin,
|
|
91
|
+
author = {Thambawita, Vajira},
|
|
92
|
+
title = {torchtsetlin: GPU-enabled, PyTorch-native Tsetlin machines},
|
|
93
|
+
year = {2026},
|
|
94
|
+
url = {https://github.com/vlbthambawita/torchtsetlin}
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## License
|
|
99
|
+
|
|
100
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=64", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "torchtsetlin"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "GPU-enabled, PyTorch-native Tsetlin Machine framework: models, data preparation, training, evaluation, interpretation and visualization."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [{ name = "Vajira Thambawita", email = "vajira@simula.no" }]
|
|
13
|
+
keywords = ["tsetlin machine", "pytorch", "interpretable machine learning", "logic-based learning", "gpu"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 3 - Alpha",
|
|
16
|
+
"Intended Audience :: Science/Research",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3.9",
|
|
20
|
+
"Programming Language :: Python :: 3.10",
|
|
21
|
+
"Programming Language :: Python :: 3.11",
|
|
22
|
+
"Programming Language :: Python :: 3.12",
|
|
23
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
24
|
+
]
|
|
25
|
+
dependencies = [
|
|
26
|
+
"torch>=2.0",
|
|
27
|
+
"numpy>=1.22",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[project.optional-dependencies]
|
|
31
|
+
viz = ["matplotlib>=3.5"]
|
|
32
|
+
vision = ["torchvision>=0.15"]
|
|
33
|
+
sklearn = ["scikit-learn>=1.1"]
|
|
34
|
+
docs = [
|
|
35
|
+
"mkdocs>=1.5",
|
|
36
|
+
"mkdocs-material>=9.4",
|
|
37
|
+
"mkdocstrings[python]>=0.24",
|
|
38
|
+
"mkdocs-autorefs>=0.5",
|
|
39
|
+
]
|
|
40
|
+
dev = [
|
|
41
|
+
"pytest>=7",
|
|
42
|
+
"pytest-timeout",
|
|
43
|
+
"matplotlib>=3.5",
|
|
44
|
+
"scikit-learn>=1.1",
|
|
45
|
+
"torchvision>=0.15",
|
|
46
|
+
"ruff",
|
|
47
|
+
"build",
|
|
48
|
+
"twine",
|
|
49
|
+
]
|
|
50
|
+
all = ["torchtsetlin[viz,vision,sklearn,docs,dev]"]
|
|
51
|
+
|
|
52
|
+
[project.urls]
|
|
53
|
+
Homepage = "https://github.com/vlbthambawita/torchtsetlin"
|
|
54
|
+
Documentation = "https://vlbthambawita.github.io/torchtsetlin/"
|
|
55
|
+
Repository = "https://github.com/vlbthambawita/torchtsetlin"
|
|
56
|
+
Issues = "https://github.com/vlbthambawita/torchtsetlin/issues"
|
|
57
|
+
|
|
58
|
+
[tool.setuptools]
|
|
59
|
+
package-dir = { "" = "src" }
|
|
60
|
+
|
|
61
|
+
[tool.setuptools.packages.find]
|
|
62
|
+
where = ["src"]
|
|
63
|
+
|
|
64
|
+
[tool.setuptools.package-data]
|
|
65
|
+
torchtsetlin = ["py.typed"]
|
|
66
|
+
|
|
67
|
+
[tool.pytest.ini_options]
|
|
68
|
+
testpaths = ["tests"]
|
|
69
|
+
addopts = "-ra"
|
|
70
|
+
timeout = 600
|
|
71
|
+
|
|
72
|
+
[tool.ruff]
|
|
73
|
+
line-length = 100
|
|
74
|
+
target-version = "py39"
|
|
75
|
+
src = ["src", "tests"]
|
|
76
|
+
|
|
77
|
+
[tool.ruff.lint]
|
|
78
|
+
select = ["E", "F", "I", "W", "B", "UP"]
|
|
79
|
+
# UP006/UP007/UP035/UP045: keep typing.Optional/List/... for Python 3.9 runtime compatibility.
|
|
80
|
+
ignore = ["E501", "B028", "UP006", "UP007", "UP035", "UP045", "E731", "B905"]
|
|
81
|
+
|
|
82
|
+
[tool.ruff.lint.isort]
|
|
83
|
+
known-first-party = ["torchtsetlin"]
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""torchtsetlin — GPU-enabled, PyTorch-native Tsetlin machines.
|
|
2
|
+
|
|
3
|
+
Quick start::
|
|
4
|
+
|
|
5
|
+
import torchtsetlin as tt
|
|
6
|
+
|
|
7
|
+
model = tt.TsetlinMachine(n_features=12, n_classes=2, n_clauses=20, T=15, s=3.9).to("cuda")
|
|
8
|
+
for x, y in loader: # Boolean features, integer labels
|
|
9
|
+
model.update(x.cuda(), y.cuda()) # learn (Type I / Type II feedback)
|
|
10
|
+
pred = model.predict(x_test.cuda()) # argmax of the vote sums
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from . import data, functional, interpret, metrics, viz
|
|
14
|
+
from .models import (
|
|
15
|
+
CoalescedTsetlinMachine,
|
|
16
|
+
Conv1dTsetlinMachine,
|
|
17
|
+
ConvCoalescedTsetlinMachine,
|
|
18
|
+
ConvRegressionTsetlinMachine,
|
|
19
|
+
ConvTsetlinMachine,
|
|
20
|
+
RegressionTsetlinMachine,
|
|
21
|
+
TsetlinMachine,
|
|
22
|
+
TsetlinMachineBase,
|
|
23
|
+
)
|
|
24
|
+
from .train import (
|
|
25
|
+
Callback,
|
|
26
|
+
CSVLogger,
|
|
27
|
+
EarlyStopping,
|
|
28
|
+
History,
|
|
29
|
+
HyperparameterSchedule,
|
|
30
|
+
LambdaCallback,
|
|
31
|
+
ModelCheckpoint,
|
|
32
|
+
ProgressLogger,
|
|
33
|
+
StateSummaryLogger,
|
|
34
|
+
Trainer,
|
|
35
|
+
evaluate,
|
|
36
|
+
predict,
|
|
37
|
+
)
|
|
38
|
+
from .utils import seed_everything
|
|
39
|
+
|
|
40
|
+
__version__ = "0.1.0"
|
|
41
|
+
__all__ = [
|
|
42
|
+
"__version__",
|
|
43
|
+
# sub-packages
|
|
44
|
+
"data",
|
|
45
|
+
"functional",
|
|
46
|
+
"interpret",
|
|
47
|
+
"metrics",
|
|
48
|
+
"viz",
|
|
49
|
+
# models
|
|
50
|
+
"TsetlinMachineBase",
|
|
51
|
+
"TsetlinMachine",
|
|
52
|
+
"CoalescedTsetlinMachine",
|
|
53
|
+
"RegressionTsetlinMachine",
|
|
54
|
+
"ConvTsetlinMachine",
|
|
55
|
+
"ConvCoalescedTsetlinMachine",
|
|
56
|
+
"ConvRegressionTsetlinMachine",
|
|
57
|
+
"Conv1dTsetlinMachine",
|
|
58
|
+
# training
|
|
59
|
+
"Trainer",
|
|
60
|
+
"evaluate",
|
|
61
|
+
"predict",
|
|
62
|
+
"History",
|
|
63
|
+
"Callback",
|
|
64
|
+
"EarlyStopping",
|
|
65
|
+
"ModelCheckpoint",
|
|
66
|
+
"CSVLogger",
|
|
67
|
+
"LambdaCallback",
|
|
68
|
+
"HyperparameterSchedule",
|
|
69
|
+
"ProgressLogger",
|
|
70
|
+
"StateSummaryLogger",
|
|
71
|
+
# utils
|
|
72
|
+
"seed_everything",
|
|
73
|
+
]
|