--- license: mit tags: - pytorch - safetensors - threshold-logic - neuromorphic --- # threshold-2outof8 At-least-two detector for 8 inputs. Fires when 2 or more bits are set. ## Circuit ``` x₀ x₁ x₂ x₃ x₄ x₅ x₆ x₇ │ │ │ │ │ │ │ │ └──┴──┴──┴──┼──┴──┴──┴──┘ ▼ ┌─────────┐ │ w: all 1│ │ b: -2 │ └─────────┘ │ ▼ HW ≥ 2 ``` ## Mechanism - Sum = (number of 1s) - 2 - Fires when Hamming weight ≥ 2 A single active input isn't enough. Needs corroboration from at least one other. ## k-out-of-8 Family | Circuit | Bias | Fires when | |---------|------|------------| | 1-out-of-8 | -1 | HW ≥ 1 | | **2-out-of-8** | **-2** | **HW ≥ 2 (this)** | | 3-out-of-8 | -3 | HW ≥ 3 | | ... | ... | ... | All share weights [1,1,1,1,1,1,1,1]. Only the bias differs. ## Parameters | | | |---|---| | Weights | [1, 1, 1, 1, 1, 1, 1, 1] | | Bias | -2 | | Total | 9 parameters | ## Usage ```python from safetensors.torch import load_file import torch w = load_file('model.safetensors') def at_least_2(bits): inputs = torch.tensor([float(b) for b in bits]) return int((inputs * w['weight']).sum() + w['bias'] >= 0) ``` ## Files ``` threshold-2outof8/ ├── model.safetensors ├── model.py ├── config.json └── README.md ``` ## License MIT