--- license: mit tags: - pytorch - safetensors - threshold-logic - neuromorphic --- # threshold-or4 A 1-of-4 threshold gate. Any single active input is enough to fire. ## Circuit ``` x1 x2 x3 x4 │ │ │ │ └───┴───┴───┘ │ ▼ ┌─────────┐ │w: 1,1,1,1│ │ b: -1 │ └─────────┘ │ ▼ OR4(x1,x2,x3,x4) ``` ## Mechanism Same weights as AND4, but bias -1 instead of -4. A single vote suffices: | x1 | x2 | x3 | x4 | sum | output | |----|----|----|-----|-----|--------| | 0 | 0 | 0 | 0 | -1 | 0 | | 0 | 0 | 0 | 1 | 0 | 1 | | ... | ... | ... | ... | ... | 1 | | 1 | 1 | 1 | 1 | 3 | 1 | ## Parameters | | | |---|---| | Weights | [1, 1, 1, 1] | | Bias | -1 | | Magnitude | 5 | | Total | 5 parameters | ## Optimality Exhaustive enumeration of all 1,683 weight configurations at magnitudes 0-5 confirms this circuit is **at minimum magnitude (5)**. There is exactly 1 valid configuration at magnitude 5, and no valid configurations exist below it. | Magnitude | Valid Configs | |-----------|---------------| | 0-4 | 0 | | 5 | 1 | ## Properties - Linearly separable (single neuron suffices) - De Morgan dual: OR4(x1,x2,x3,x4) = NOT(AND4(NOT(x1), NOT(x2), NOT(x3), NOT(x4))) ## Usage ```python from safetensors.torch import load_file import torch w = load_file('model.safetensors') def or4_gate(x1, x2, x3, x4): inputs = torch.tensor([float(x1), float(x2), float(x3), float(x4)]) return int((inputs * w['weight']).sum() + w['bias'] >= 0) assert or4_gate(0, 0, 0, 0) == 0 assert or4_gate(0, 0, 0, 1) == 1 assert or4_gate(1, 1, 1, 1) == 1 ``` ## Files ``` threshold-or4/ ├── model.safetensors ├── model.py ├── config.json ├── create_safetensors.py └── README.md ``` ## License MIT