--- license: mit tags: - pytorch - safetensors - threshold-logic - neuromorphic --- # threshold-exactly4outof8 Exactly-4-out-of-8 detector. Fires when precisely half the inputs are active. The tie detector. ## Circuit ``` x₀ x₁ x₂ x₃ x₄ x₅ x₆ x₇ │ │ │ │ │ │ │ │ └──┴──┴──┴──┼──┴──┴──┴──┘ │ ┌───────┴───────┐ ▼ ▼ ┌─────────┐ ┌─────────┐ │ ≥ 4 │ │ ≤ 4 │ │ b = -4 │ │ b = +4 │ └─────────┘ └─────────┘ │ │ └───────┬───────┘ ▼ ┌─────────┐ │ AND │ └─────────┘ │ ▼ tie? ``` ## The Center of the Distribution HW = 4 is special: - **Maximum entropy**: C(8,4) = 70 is the largest binomial coefficient for n=8 - **Perfect balance**: 4 ones, 4 zeros - **Self-complementary**: Flipping all bits maps HW=4 to itself (though not necessarily the same pattern) This circuit fires on 70 of 256 inputs - the mode of the distribution. ## Neither Majority Nor Minority | Circuit | Condition | Fires at HW=4? | |---------|-----------|----------------| | Majority | HW ≥ 5 | No | | Minority | HW ≤ 3 | No | | **Exactly4** | HW = 4 | **Yes** | Exactly4 catches what both Majority and Minority miss. It's the gap between them - the deadlock. ## Threshold Arithmetic **AtLeast4**: Sum all inputs with weight +1, subtract 4. ``` x₀ + x₁ + x₂ + x₃ + x₄ + x₅ + x₆ + x₇ - 4 ≥ 0 ``` Fires when 4 or more inputs are active. **AtMost4**: Sum all inputs with weight -1, add 4. ``` -x₀ - x₁ - x₂ - x₃ - x₄ - x₅ - x₆ - x₇ + 4 ≥ 0 ``` Fires when 4 or fewer inputs are active. Their intersection is exactly 4. ## The Binomial Peak | HW | C(8,k) | Exactly4? | |----|--------|-----------| | 0 | 1 | - | | 1 | 8 | - | | 2 | 28 | - | | 3 | 56 | - | | **4** | **70** | **YES** | | 5 | 56 | - | | 6 | 28 | - | | 7 | 8 | - | | 8 | 1 | - | The distribution is symmetric around 4. This circuit sits at the apex. ## Parameters | Component | Weights | Bias | |-----------|---------|------| | AtLeast4 | all +1 | -4 | | AtMost4 | all -1 | +4 | | AND | [+1, +1] | -2 | **Total: 3 neurons, 21 parameters, 2 layers** ## Usage ```python from safetensors.torch import load_file import torch w = load_file('model.safetensors') def exactly4(bits): inp = torch.tensor([float(b) for b in bits]) atleast = int((inp * w['atleast.weight']).sum() + w['atleast.bias'] >= 0) atmost = int((inp * w['atmost.weight']).sum() + w['atmost.bias'] >= 0) comb = torch.tensor([float(atleast), float(atmost)]) return int((comb * w['and.weight']).sum() + w['and.bias'] >= 0) # Balanced: alternating pattern bits = [1, 0, 1, 0, 1, 0, 1, 0] print(exactly4(bits)) # 1 # Majority (5) - not a tie bits = [1, 1, 1, 0, 1, 0, 1, 0] print(exactly4(bits)) # 0 ``` ## Files ``` threshold-exactly4outof8/ ├── model.safetensors ├── model.py ├── config.json └── README.md ``` ## License MIT