phanerozoic's picture
Upload README.md with huggingface_hub
9e698dd verified
---
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