--- license: mit tags: - pytorch - safetensors - threshold-logic - neuromorphic --- # threshold-1outof8 At-least-one detector for 8 inputs. Equivalent to an 8-input OR gate. ## Circuit ``` x₀ x₁ x₂ x₃ x₄ x₅ x₆ x₇ │ │ │ │ │ │ │ │ └──┴──┴──┴──┼──┴──┴──┴──┘ ▼ ┌─────────┐ │ w: all 1│ │ b: -1 │ └─────────┘ │ ▼ HW ≥ 1 ``` ## Mechanism With uniform weights of 1 and bias -1, the neuron fires when at least one input is active: - Sum = (number of 1s) - 1 - Fires when sum ≥ 0, i.e., when Hamming weight ≥ 1 This is the loosest threshold in the k-out-of-8 family. ## k-out-of-8 Family | Circuit | Bias | Fires when | |---------|------|------------| | **1-out-of-8** | **-1** | **HW ≥ 1 (this)** | | 2-out-of-8 | -2 | HW ≥ 2 | | ... | ... | ... | | 8-out-of-8 | -8 | HW = 8 | 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 | -1 | | Total | 9 parameters | ## Usage ```python from safetensors.torch import load_file import torch w = load_file('model.safetensors') def at_least_1(bits): inputs = torch.tensor([float(b) for b in bits]) return int((inputs * w['weight']).sum() + w['bias'] >= 0) ``` ## Files ``` threshold-1outof8/ ├── model.safetensors ├── model.py ├── config.json └── README.md ``` ## License MIT