# cair/tmu architecture

> Architecture diagram of the GitHub repository cair/tmu, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cair/tmu
- Repository: https://github.com/cair/tmu

## Overview

TMU is a Python-centered suite of Tsetlin Machine implementations, with C/CUDA acceleration and experimental model extensions. The main workflow is to obtain data, optionally binarize it, train a model, and produce predictions. Separate branches cover regression, autoencoding, composite collaboration, and experimental classifiers. The graph preserves the documented variants and major infrastructure; several relationships are omitted where the sampled excerpts do not establish runtime calls.

Main entry points: [`tmu/models/base.py`](https://github.com/cair/tmu/blob/main/tmu/models/base.py) (Shared model base), [`tmu/weight_bank/weight_bank.py`](https://github.com/cair/tmu/blob/main/tmu/weight_bank/weight_bank.py) (Weight bank), [`tmu/models/classification/vanilla_classifier.py`](https://github.com/cair/tmu/blob/main/tmu/models/classification/vanilla_classifier.py) (Vanilla classifier), [`tmu/composite/composite.py`](https://github.com/cair/tmu/blob/main/tmu/composite/composite.py) (Composite runner)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data preparation"]
  node_datasets["Dataset loaders"]
  node_binarizer["Standard binarizer<br/>[binarizer.py]"]
end

subgraph group_models["Model implementations"]
  node_vanilla["Vanilla classifier"]
  node_coalesced["Coalesced classifier"]
  node_regressor["Vanilla regressor"]
  node_autoencoder["Autoencoder<br/>[autoencoder.py]"]
  node_base["Shared model base<br/>[base.py]"]
end

subgraph group_engines["Clause and weight engines"]
  node_clause["Dense clause bank<br/>[clause_bank.py]"]
  node_sparse["Sparse clause bank"]
  node_cuda["CUDA clause bank"]
  node_weights["Weight bank<br/>[weight_bank.py]"]
  node_cpp_classifier["C++ classifier<br/>[tm_vanilla.h]"]
  node_cpp_clause["C++ dense clauses<br/>[tm_clause_dense.h]"]
  node_cpp_bindings["C++ Python bindings<br/>[tmulibcpp.cpp]"]
end

subgraph group_extensions["Extended models"]
  node_multioutput["Multi-output classifier"]
  node_multichannel["Multichannel classifier"]
  node_one_vs_one["One-vs-one classifier"]
  node_relational["Relational classifier"]
  node_attention["Attention model<br/>[attention.py]"]
end

subgraph group_composite["Composite learning"]
  node_composite_runner["Composite runner<br/>[composite.py]"]
  node_components["Specialized components"]
  node_gates["Component gates"]
  node_tuner["Composite tuner<br/>[tuner.py]"]
end

node_user(("Researcher or application"))

node_user -->|"loads data"| node_datasets
node_user -->|"trains or predicts"| node_vanilla
node_base -->|"selects backend"| node_clause
node_base -->|"selects backend"| node_sparse
node_base -->|"selects backend"| node_cuda
node_vanilla -->|"inherits from"| node_base
node_coalesced -.->|"inherits from"| node_base
node_regressor -->|"inherits from"| node_base
node_autoencoder -->|"inherits from"| node_base
node_vanilla -->|"uses weights"| node_weights
node_regressor -->|"uses weights"| node_weights
node_autoencoder -->|"uses weights"| node_weights
node_multioutput -->|"inherits from"| node_base
node_multioutput -->|"uses weights"| node_weights
node_relational -->|"inherits from"| node_base
node_relational -->|"uses weights"| node_weights
node_cpp_classifier -->|"uses clauses"| node_cpp_clause
node_cpp_bindings -->|"binds classifier"| node_cpp_classifier
node_cpp_clause -.->|"C acceleration"| node_clause
node_composite_runner -->|"runs components"| node_components
node_composite_runner -->|"uses gates"| node_gates
node_tuner -.->|"tunes composites"| node_composite_runner

click node_datasets "https://github.com/cair/tmu/tree/main/tmu/data"
click node_binarizer "https://github.com/cair/tmu/blob/main/tmu/preprocessing/standard_binarizer/binarizer.py"
click node_vanilla "https://github.com/cair/tmu/blob/main/tmu/models/classification/vanilla_classifier.py"
click node_coalesced "https://github.com/cair/tmu/blob/main/tmu/models/classification/coalesced_classifier.py"
click node_regressor "https://github.com/cair/tmu/blob/main/tmu/models/regression/vanilla_regressor.py"
click node_autoencoder "https://github.com/cair/tmu/blob/main/tmu/models/autoencoder/autoencoder.py"
click node_base "https://github.com/cair/tmu/blob/main/tmu/models/base.py"
click node_clause "https://github.com/cair/tmu/blob/main/tmu/clause_bank/clause_bank.py"
click node_sparse "https://github.com/cair/tmu/blob/main/tmu/clause_bank/clause_bank_sparse.py"
click node_cuda "https://github.com/cair/tmu/blob/main/tmu/clause_bank/clause_bank_cuda.py"
click node_weights "https://github.com/cair/tmu/blob/main/tmu/weight_bank/weight_bank.py"
click node_cpp_classifier "https://github.com/cair/tmu/blob/main/tmu/lib/cpp/include/models/classifiers/tm_vanilla.h"
click node_cpp_clause "https://github.com/cair/tmu/blob/main/tmu/lib/cpp/include/tm_clause_dense.h"
click node_cpp_bindings "https://github.com/cair/tmu/blob/main/tmu/lib/cpp/nb/tmulibcpp.cpp"
click node_multioutput "https://github.com/cair/tmu/blob/main/tmu/experimental/models/multioutput_classifier.py"
click node_multichannel "https://github.com/cair/tmu/blob/main/tmu/experimental/models/multichannel_classifier.py"
click node_one_vs_one "https://github.com/cair/tmu/blob/main/tmu/experimental/models/one_vs_one_classifier.py"
click node_relational "https://github.com/cair/tmu/blob/main/tmu/experimental/models/relational/vanilla_relational.py"
click node_attention "https://github.com/cair/tmu/blob/main/tmu/experimental/models/attention.py"
click node_composite_runner "https://github.com/cair/tmu/blob/main/tmu/composite/composite.py"
click node_components "https://github.com/cair/tmu/tree/main/tmu/composite/components"
click node_gates "https://github.com/cair/tmu/tree/main/tmu/composite/gating"
click node_tuner "https://github.com/cair/tmu/blob/main/tmu/composite/tuner.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_datasets,node_binarizer toneBlue
class node_vanilla,node_coalesced,node_regressor,node_autoencoder,node_base toneAmber
class node_clause,node_sparse,node_cuda,node_weights,node_cpp_classifier,node_cpp_clause,node_cpp_bindings toneMint
class node_multioutput,node_multichannel,node_one_vs_one,node_relational,node_attention toneRose
class node_composite_runner,node_components,node_gates,node_tuner,node_user toneIndigo
```

## Components

### Data preparation

- [Dataset loaders](https://github.com/cair/tmu/tree/main/tmu/data): `tmu/data`
- [Standard binarizer](https://github.com/cair/tmu/blob/main/tmu/preprocessing/standard_binarizer/binarizer.py): `tmu/preprocessing/standard_binarizer/binarizer.py`

### Model implementations

- [Vanilla classifier](https://github.com/cair/tmu/blob/main/tmu/models/classification/vanilla_classifier.py): `tmu/models/classification/vanilla_classifier.py`
- [Coalesced classifier](https://github.com/cair/tmu/blob/main/tmu/models/classification/coalesced_classifier.py): `tmu/models/classification/coalesced_classifier.py`
- [Vanilla regressor](https://github.com/cair/tmu/blob/main/tmu/models/regression/vanilla_regressor.py): `tmu/models/regression/vanilla_regressor.py`
- [Autoencoder](https://github.com/cair/tmu/blob/main/tmu/models/autoencoder/autoencoder.py): `tmu/models/autoencoder/autoencoder.py`
- [Shared model base](https://github.com/cair/tmu/blob/main/tmu/models/base.py): `tmu/models/base.py`

### Clause and weight engines

- [Dense clause bank](https://github.com/cair/tmu/blob/main/tmu/clause_bank/clause_bank.py): `tmu/clause_bank/clause_bank.py`
- [Sparse clause bank](https://github.com/cair/tmu/blob/main/tmu/clause_bank/clause_bank_sparse.py): `tmu/clause_bank/clause_bank_sparse.py`
- [CUDA clause bank](https://github.com/cair/tmu/blob/main/tmu/clause_bank/clause_bank_cuda.py): `tmu/clause_bank/clause_bank_cuda.py`
- [Weight bank](https://github.com/cair/tmu/blob/main/tmu/weight_bank/weight_bank.py): `tmu/weight_bank/weight_bank.py`
- [C++ classifier](https://github.com/cair/tmu/blob/main/tmu/lib/cpp/include/models/classifiers/tm_vanilla.h): `tmu/lib/cpp/include/models/classifiers/tm_vanilla.h`
- [C++ dense clauses](https://github.com/cair/tmu/blob/main/tmu/lib/cpp/include/tm_clause_dense.h): `tmu/lib/cpp/include/tm_clause_dense.h`
- [C++ Python bindings](https://github.com/cair/tmu/blob/main/tmu/lib/cpp/nb/tmulibcpp.cpp): `tmu/lib/cpp/nb/tmulibcpp.cpp`

### Extended models

- [Multi-output classifier](https://github.com/cair/tmu/blob/main/tmu/experimental/models/multioutput_classifier.py): `tmu/experimental/models/multioutput_classifier.py`
- [Multichannel classifier](https://github.com/cair/tmu/blob/main/tmu/experimental/models/multichannel_classifier.py): `tmu/experimental/models/multichannel_classifier.py`
- [One-vs-one classifier](https://github.com/cair/tmu/blob/main/tmu/experimental/models/one_vs_one_classifier.py): `tmu/experimental/models/one_vs_one_classifier.py`
- [Relational classifier](https://github.com/cair/tmu/blob/main/tmu/experimental/models/relational/vanilla_relational.py): `tmu/experimental/models/relational/vanilla_relational.py`
- [Attention model](https://github.com/cair/tmu/blob/main/tmu/experimental/models/attention.py): `tmu/experimental/models/attention.py`

### Composite learning

- [Composite runner](https://github.com/cair/tmu/blob/main/tmu/composite/composite.py): `tmu/composite/composite.py`
- [Specialized components](https://github.com/cair/tmu/tree/main/tmu/composite/components): `tmu/composite/components`
- [Component gates](https://github.com/cair/tmu/tree/main/tmu/composite/gating): `tmu/composite/gating`
- [Composite tuner](https://github.com/cair/tmu/blob/main/tmu/composite/tuner.py): `tmu/composite/tuner.py`

### Other components

- **Researcher or application**

## Connections

- Researcher or application → Dataset loaders: loads data
- Researcher or application → Vanilla classifier: trains or predicts
- Shared model base → Dense clause bank: selects backend (evidence: `tmu/models/base.py`)
- Shared model base → Sparse clause bank: selects backend (evidence: `tmu/models/base.py`)
- Shared model base → CUDA clause bank: selects backend (evidence: `tmu/models/base.py`)
- Vanilla classifier → Shared model base: inherits from (evidence: `tmu/models/classification/vanilla_classifier.py`)
- Coalesced classifier → Shared model base: inherits from
- Vanilla regressor → Shared model base: inherits from (evidence: `tmu/models/regression/vanilla_regressor.py`)
- Autoencoder → Shared model base: inherits from (evidence: `tmu/models/autoencoder/autoencoder.py`)
- Vanilla classifier → Weight bank: uses weights (evidence: `tmu/models/classification/vanilla_classifier.py`)
- Vanilla regressor → Weight bank: uses weights (evidence: `tmu/models/regression/vanilla_regressor.py`)
- Autoencoder → Weight bank: uses weights (evidence: `tmu/models/autoencoder/autoencoder.py`)
- Multi-output classifier → Shared model base: inherits from (evidence: `tmu/experimental/models/multioutput_classifier.py`)
- Multi-output classifier → Weight bank: uses weights (evidence: `tmu/experimental/models/multioutput_classifier.py`)
- Relational classifier → Shared model base: inherits from (evidence: `tmu/experimental/models/relational/vanilla_relational.py`)
- Relational classifier → Weight bank: uses weights (evidence: `tmu/experimental/models/relational/vanilla_relational.py`)
- C++ classifier → C++ dense clauses: uses clauses (evidence: `tmu/lib/cpp/include/models/classifiers/tm_vanilla.h`)
- C++ Python bindings → C++ classifier: binds classifier (evidence: `tmu/lib/cpp/nb/tmulibcpp.cpp`)
- C++ dense clauses → Dense clause bank: C acceleration
- Composite runner → Specialized components: runs components (evidence: `tmu/composite/composite.py`)
- Composite runner → Component gates: uses gates (evidence: `tmu/composite/composite.py`)
- Composite tuner → Composite runner: tunes composites
