--- license: mit tags: - pytorch - safetensors - threshold-logic - neuromorphic - modular-arithmetic --- # threshold-mod8 Computes Hamming weight mod 8 directly on inputs. Single-layer circuit. ## Circuit ``` x₀ x₁ x₂ x₃ x₄ x₅ x₆ x₇ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ w: 1 1 1 1 1 1 1 -7 └──┴──┴──┴──┼──┴──┴──┴──┘ ▼ ┌─────────┐ │ b: 0 │ └─────────┘ │ ▼ HW mod 8 ``` ## Algebraic Insight Position 8 gets weight 1-8 = -7: - Positions 1-7: weight +1 - Position 8: weight -7 ``` HW=0: sum=0 → 0 mod 8 ... HW=7: sum=7 → 7 mod 8 HW=8: sum=0 → 0 mod 8 (reset: 1+1+1+1+1+1+1-7=0) ``` The only non-trivial case is HW=8, which resets to 0. ## Parameters | | | |---|---| | Weights | [1, 1, 1, 1, 1, 1, 1, -7] | | Bias | 0 | | Total | 9 parameters | ## Usage ```python from safetensors.torch import load_file import torch w = load_file('model.safetensors') def mod8(bits): inputs = torch.tensor([float(b) for b in bits]) return int((inputs * w['weight']).sum() + w['bias']) ``` ## Files ``` threshold-mod8/ ├── model.safetensors ├── model.py ├── config.json └── README.md ``` ## License MIT