Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -9,7 +9,7 @@ tags:
|
|
| 9 |
|
| 10 |
# threshold-exactly4outof8
|
| 11 |
|
| 12 |
-
Exactly-4-out-of-8 detector. Fires when
|
| 13 |
|
| 14 |
## Circuit
|
| 15 |
|
|
@@ -21,9 +21,8 @@ Exactly-4-out-of-8 detector. Fires when exactly four inputs are active - the bal
|
|
| 21 |
βββββββββ΄ββββββββ
|
| 22 |
βΌ βΌ
|
| 23 |
βββββββββββ βββββββββββ
|
| 24 |
-
β
|
| 25 |
-
β
|
| 26 |
-
β b: -4 β β b: +4 β
|
| 27 |
βββββββββββ βββββββββββ
|
| 28 |
β β
|
| 29 |
βββββββββ¬ββββββββ
|
|
@@ -33,24 +32,104 @@ Exactly-4-out-of-8 detector. Fires when exactly four inputs are active - the bal
|
|
| 33 |
βββββββββββ
|
| 34 |
β
|
| 35 |
βΌ
|
| 36 |
-
|
| 37 |
```
|
| 38 |
|
| 39 |
-
##
|
| 40 |
|
| 41 |
-
|
| 42 |
|
| 43 |
-
|
|
|
|
|
|
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|----|--------|
|
| 47 |
-
| 0-3 | 0 |
|
| 48 |
-
| 4 | **1** |
|
| 49 |
-
| 5-8 | 0 |
|
| 50 |
|
| 51 |
-
##
|
| 52 |
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
## License
|
| 56 |
|
|
|
|
| 9 |
|
| 10 |
# threshold-exactly4outof8
|
| 11 |
|
| 12 |
+
Exactly-4-out-of-8 detector. Fires when precisely half the inputs are active. The tie detector.
|
| 13 |
|
| 14 |
## Circuit
|
| 15 |
|
|
|
|
| 21 |
βββββββββ΄ββββββββ
|
| 22 |
βΌ βΌ
|
| 23 |
βββββββββββ βββββββββββ
|
| 24 |
+
β β₯ 4 β β β€ 4 β
|
| 25 |
+
β b = -4 β β b = +4 β
|
|
|
|
| 26 |
βββββββββββ βββββββββββ
|
| 27 |
β β
|
| 28 |
βββββββββ¬ββββββββ
|
|
|
|
| 32 |
βββββββββββ
|
| 33 |
β
|
| 34 |
βΌ
|
| 35 |
+
tie?
|
| 36 |
```
|
| 37 |
|
| 38 |
+
## The Center of the Distribution
|
| 39 |
|
| 40 |
+
HW = 4 is special:
|
| 41 |
|
| 42 |
+
- **Maximum entropy**: C(8,4) = 70 is the largest binomial coefficient for n=8
|
| 43 |
+
- **Perfect balance**: 4 ones, 4 zeros
|
| 44 |
+
- **Self-complementary**: Flipping all bits maps HW=4 to itself (though not necessarily the same pattern)
|
| 45 |
|
| 46 |
+
This circuit fires on 70 of 256 inputs - the mode of the distribution.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
+
## Neither Majority Nor Minority
|
| 49 |
|
| 50 |
+
| Circuit | Condition | Fires at HW=4? |
|
| 51 |
+
|---------|-----------|----------------|
|
| 52 |
+
| Majority | HW β₯ 5 | No |
|
| 53 |
+
| Minority | HW β€ 3 | No |
|
| 54 |
+
| **Exactly4** | HW = 4 | **Yes** |
|
| 55 |
+
|
| 56 |
+
Exactly4 catches what both Majority and Minority miss. It's the gap between them - the deadlock.
|
| 57 |
+
|
| 58 |
+
## Threshold Arithmetic
|
| 59 |
+
|
| 60 |
+
**AtLeast4**: Sum all inputs with weight +1, subtract 4.
|
| 61 |
+
```
|
| 62 |
+
xβ + xβ + xβ + xβ + xβ + xβ
+ xβ + xβ - 4 β₯ 0
|
| 63 |
+
```
|
| 64 |
+
Fires when 4 or more inputs are active.
|
| 65 |
+
|
| 66 |
+
**AtMost4**: Sum all inputs with weight -1, add 4.
|
| 67 |
+
```
|
| 68 |
+
-xβ - xβ - xβ - xβ - xβ - xβ
- xβ - xβ + 4 β₯ 0
|
| 69 |
+
```
|
| 70 |
+
Fires when 4 or fewer inputs are active.
|
| 71 |
+
|
| 72 |
+
Their intersection is exactly 4.
|
| 73 |
+
|
| 74 |
+
## The Binomial Peak
|
| 75 |
+
|
| 76 |
+
| HW | C(8,k) | Exactly4? |
|
| 77 |
+
|----|--------|-----------|
|
| 78 |
+
| 0 | 1 | - |
|
| 79 |
+
| 1 | 8 | - |
|
| 80 |
+
| 2 | 28 | - |
|
| 81 |
+
| 3 | 56 | - |
|
| 82 |
+
| **4** | **70** | **YES** |
|
| 83 |
+
| 5 | 56 | - |
|
| 84 |
+
| 6 | 28 | - |
|
| 85 |
+
| 7 | 8 | - |
|
| 86 |
+
| 8 | 1 | - |
|
| 87 |
+
|
| 88 |
+
The distribution is symmetric around 4. This circuit sits at the apex.
|
| 89 |
+
|
| 90 |
+
## Parameters
|
| 91 |
+
|
| 92 |
+
| Component | Weights | Bias |
|
| 93 |
+
|-----------|---------|------|
|
| 94 |
+
| AtLeast4 | all +1 | -4 |
|
| 95 |
+
| AtMost4 | all -1 | +4 |
|
| 96 |
+
| AND | [+1, +1] | -2 |
|
| 97 |
+
|
| 98 |
+
**Total: 3 neurons, 21 parameters, 2 layers**
|
| 99 |
+
|
| 100 |
+
## Usage
|
| 101 |
+
|
| 102 |
+
```python
|
| 103 |
+
from safetensors.torch import load_file
|
| 104 |
+
import torch
|
| 105 |
+
|
| 106 |
+
w = load_file('model.safetensors')
|
| 107 |
+
|
| 108 |
+
def exactly4(bits):
|
| 109 |
+
inp = torch.tensor([float(b) for b in bits])
|
| 110 |
+
atleast = int((inp * w['atleast.weight']).sum() + w['atleast.bias'] >= 0)
|
| 111 |
+
atmost = int((inp * w['atmost.weight']).sum() + w['atmost.bias'] >= 0)
|
| 112 |
+
comb = torch.tensor([float(atleast), float(atmost)])
|
| 113 |
+
return int((comb * w['and.weight']).sum() + w['and.bias'] >= 0)
|
| 114 |
+
|
| 115 |
+
# Balanced: alternating pattern
|
| 116 |
+
bits = [1, 0, 1, 0, 1, 0, 1, 0]
|
| 117 |
+
print(exactly4(bits)) # 1
|
| 118 |
+
|
| 119 |
+
# Majority (5) - not a tie
|
| 120 |
+
bits = [1, 1, 1, 0, 1, 0, 1, 0]
|
| 121 |
+
print(exactly4(bits)) # 0
|
| 122 |
+
```
|
| 123 |
+
|
| 124 |
+
## Files
|
| 125 |
+
|
| 126 |
+
```
|
| 127 |
+
threshold-exactly4outof8/
|
| 128 |
+
βββ model.safetensors
|
| 129 |
+
βββ model.py
|
| 130 |
+
βββ config.json
|
| 131 |
+
βββ README.md
|
| 132 |
+
```
|
| 133 |
|
| 134 |
## License
|
| 135 |
|