phanerozoic commited on
Commit
6bcda71
Β·
verified Β·
1 Parent(s): eb04421

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +90 -17
README.md CHANGED
@@ -9,7 +9,7 @@ tags:
9
 
10
  # threshold-exactly3outof8
11
 
12
- Exactly-3-out-of-8 detector. Fires when exactly three inputs are active.
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
- β”‚ AtLeast3β”‚ β”‚ AtMost3 β”‚
25
- β”‚ w: +1Γ—8 β”‚ β”‚ w: -1Γ—8 β”‚
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
- (HW = 3?)
37
  ```
38
 
39
- ## Mechanism
40
 
41
- - **AtLeast3**: Fires when HW β‰₯ 3 (bias -3)
42
- - **AtMost3**: Fires when HW ≀ 3 (weights -1, bias +3)
43
- - **AND**: Exactly3 = AtLeast3 AND AtMost3
44
 
45
- ## Truth Table
 
 
46
 
47
- | HW | Result |
48
- |----|--------|
49
- | 0-2 | 0 |
50
- | 3 | **1** |
51
- | 4-8 | 0 |
52
 
53
- ## Architecture
54
 
55
- **3 neurons, 21 parameters, 2 layers**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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