phanerozoic commited on
Commit
9e698dd
Β·
verified Β·
1 Parent(s): 2978b39

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +94 -15
README.md CHANGED
@@ -9,7 +9,7 @@ tags:
9
 
10
  # threshold-exactly4outof8
11
 
12
- Exactly-4-out-of-8 detector. Fires when exactly four inputs are active - the balanced case.
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
- β”‚ AtLeast4β”‚ β”‚ AtMost4 β”‚
25
- β”‚ w: +1Γ—8 β”‚ β”‚ w: -1Γ—8 β”‚
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
- (HW = 4?)
37
  ```
38
 
39
- ## Significance
40
 
41
- This is the "tie" detector for 8 inputs - fires when exactly half are active. Neither majority nor minority.
42
 
43
- ## Truth Table
 
 
44
 
45
- | HW | Result |
46
- |----|--------|
47
- | 0-3 | 0 |
48
- | 4 | **1** |
49
- | 5-8 | 0 |
50
 
51
- ## Architecture
52
 
53
- **3 neurons, 21 parameters, 2 layers**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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