Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -9,7 +9,7 @@ tags:
|
|
| 9 |
|
| 10 |
# threshold-exactly3outof8
|
| 11 |
|
| 12 |
-
Exactly-3-out-of-8 detector. Fires when
|
| 13 |
|
| 14 |
## Circuit
|
| 15 |
|
|
@@ -21,9 +21,8 @@ Exactly-3-out-of-8 detector. Fires when exactly three inputs are active.
|
|
| 21 |
βββββββββ΄ββββββββ
|
| 22 |
βΌ βΌ
|
| 23 |
βββββββββββ βββββββββββ
|
| 24 |
-
β
|
| 25 |
-
β
|
| 26 |
-
β b: -3 β β b: +3 β
|
| 27 |
βββββββββββ βββββββββββ
|
| 28 |
β β
|
| 29 |
βββββββββ¬ββββββββ
|
|
@@ -33,26 +32,100 @@ Exactly-3-out-of-8 detector. Fires when exactly three inputs are active.
|
|
| 33 |
βββββββββββ
|
| 34 |
β
|
| 35 |
βΌ
|
| 36 |
-
|
| 37 |
```
|
| 38 |
|
| 39 |
-
##
|
| 40 |
|
| 41 |
-
|
| 42 |
-
- **AtMost3**: Fires when HW β€ 3 (weights -1, bias +3)
|
| 43 |
-
- **AND**: Exactly3 = AtLeast3 AND AtMost3
|
| 44 |
|
| 45 |
-
|
|
|
|
|
|
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|----|--------|
|
| 49 |
-
| 0-2 | 0 |
|
| 50 |
-
| 3 | **1** |
|
| 51 |
-
| 4-8 | 0 |
|
| 52 |
|
| 53 |
-
##
|
| 54 |
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
## License
|
| 58 |
|
|
|
|
| 9 |
|
| 10 |
# threshold-exactly3outof8
|
| 11 |
|
| 12 |
+
Exactly-3-out-of-8 detector. Fires when precisely three inputs are active. The triple detector.
|
| 13 |
|
| 14 |
## Circuit
|
| 15 |
|
|
|
|
| 21 |
βββββββββ΄ββββββββ
|
| 22 |
βΌ βΌ
|
| 23 |
βββββββββββ βββββββββββ
|
| 24 |
+
β β₯ 3 β β β€ 3 β
|
| 25 |
+
β b = -3 β β b = +3 β
|
|
|
|
| 26 |
βββββββββββ βββββββββββ
|
| 27 |
β β
|
| 28 |
βββββββββ¬ββββββββ
|
|
|
|
| 32 |
βββββββββββ
|
| 33 |
β
|
| 34 |
βΌ
|
| 35 |
+
exactly 3?
|
| 36 |
```
|
| 37 |
|
| 38 |
+
## Why Three Matters
|
| 39 |
|
| 40 |
+
Three is the smallest odd number greater than one. In voting:
|
|
|
|
|
|
|
| 41 |
|
| 42 |
+
- **Byzantine fault tolerance**: 3f+1 nodes tolerate f failures
|
| 43 |
+
- **Quorum systems**: Often require βn/2β + 1 = 3 for n=4
|
| 44 |
+
- **Graph theory**: A triangle is the minimal clique
|
| 45 |
|
| 46 |
+
There are C(8,3) = 56 input patterns that fire this circuit - exactly double the pairs.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
+
## The Threshold Sandwich
|
| 49 |
|
| 50 |
+
The circuit squeezes Hamming weight between two bounds:
|
| 51 |
+
|
| 52 |
+
```
|
| 53 |
+
Lower bound (AtLeast3): Upper bound (AtMost3):
|
| 54 |
+
+xβ + xβ + ... + xβ -xβ - xβ - ... - xβ
|
| 55 |
+
βββββββββββββββββββββ βββββββββββββββββββββ
|
| 56 |
+
-3 +3
|
| 57 |
+
|
| 58 |
+
fires if HW β₯ 3 fires if HW β€ 3
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
The AND gate demands both conditions simultaneously. Only HW = 3 satisfies both.
|
| 62 |
+
|
| 63 |
+
## Input Distribution
|
| 64 |
+
|
| 65 |
+
| HW | Count | Exactly3 |
|
| 66 |
+
|----|-------|----------|
|
| 67 |
+
| 0 | 1 | 0 |
|
| 68 |
+
| 1 | 8 | 0 |
|
| 69 |
+
| 2 | 28 | 0 |
|
| 70 |
+
| **3** | **56** | **1** |
|
| 71 |
+
| 4 | 70 | 0 |
|
| 72 |
+
| 5 | 56 | 0 |
|
| 73 |
+
| 6 | 28 | 0 |
|
| 74 |
+
| 7 | 8 | 0 |
|
| 75 |
+
| 8 | 1 | 0 |
|
| 76 |
+
|
| 77 |
+
The binomial distribution peaks at HW=4, but HW=3 and HW=5 are tied at 56 patterns each.
|
| 78 |
+
|
| 79 |
+
## Parameters
|
| 80 |
+
|
| 81 |
+
| Component | Weights | Bias |
|
| 82 |
+
|-----------|---------|------|
|
| 83 |
+
| AtLeast3 | all +1 | -3 |
|
| 84 |
+
| AtMost3 | all -1 | +3 |
|
| 85 |
+
| AND | [+1, +1] | -2 |
|
| 86 |
+
|
| 87 |
+
**Total: 3 neurons, 21 parameters, 2 layers**
|
| 88 |
+
|
| 89 |
+
## Duality with Exactly5
|
| 90 |
+
|
| 91 |
+
Exactly3 and Exactly5 are complementary around the center:
|
| 92 |
+
|
| 93 |
+
| Circuit | Fires on | Count | Complement |
|
| 94 |
+
|---------|----------|-------|------------|
|
| 95 |
+
| Exactly3 | HW = 3 | 56 | HW = 5 |
|
| 96 |
+
| Exactly5 | HW = 5 | 56 | HW = 3 |
|
| 97 |
+
|
| 98 |
+
If you flip all 8 bits, an Exactly3 input becomes Exactly5, and vice versa.
|
| 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 exactly3(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 |
+
# Triangle: positions 0, 3, 7 active
|
| 116 |
+
bits = [1, 0, 0, 1, 0, 0, 0, 1]
|
| 117 |
+
print(exactly3(bits)) # 1
|
| 118 |
+
```
|
| 119 |
+
|
| 120 |
+
## Files
|
| 121 |
+
|
| 122 |
+
```
|
| 123 |
+
threshold-exactly3outof8/
|
| 124 |
+
βββ model.safetensors
|
| 125 |
+
βββ model.py
|
| 126 |
+
βββ config.json
|
| 127 |
+
βββ README.md
|
| 128 |
+
```
|
| 129 |
|
| 130 |
## License
|
| 131 |
|