--- license: mit tags: - pytorch - safetensors - threshold-logic - neuromorphic - modular-arithmetic --- # threshold-mod9 Trivial case: computes Hamming weight mod 9 for 8-bit inputs. Since max HW is 8 < 9, this is just HW. ## Circuit ``` x₀ x₁ x₂ x₃ x₄ x₅ x₆ x₇ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ w: 1 1 1 1 1 1 1 1 └──┴──┴──┴──┼──┴──┴──┴──┘ ▼ ┌─────────┐ │ b: 0 │ └─────────┘ │ ▼ HW (= HW mod 9) ``` ## Why Trivial? For mod m where m > (number of inputs), no reset ever occurs: - 8 inputs → max HW = 8 - 8 mod 9 = 8 (no wraparound) The circuit just sums the inputs. It's a degenerate case included for completeness of the MOD-m family. ## Parameters | | | |---|---| | Weights | [1, 1, 1, 1, 1, 1, 1, 1] | | Bias | 0 | | Total | 9 parameters | ## Usage ```python from safetensors.torch import load_file import torch w = load_file('model.safetensors') def mod9(bits): # Actually just HW inputs = torch.tensor([float(b) for b in bits]) return int((inputs * w['weight']).sum() + w['bias']) ``` ## Files ``` threshold-mod9/ ├── model.safetensors ├── model.py ├── config.json └── README.md ``` ## License MIT