Upload folder using huggingface_hub
Browse files- README.md +130 -0
- config.json +9 -0
- model.py +18 -0
- model.safetensors +3 -0
README.md
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
tags:
|
| 4 |
+
- pytorch
|
| 5 |
+
- safetensors
|
| 6 |
+
- threshold-logic
|
| 7 |
+
- neuromorphic
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
# threshold-atmost2outof8
|
| 11 |
+
|
| 12 |
+
At-most-2-out-of-8 detector. Fires when two or fewer inputs are active. The error-tolerance bound.
|
| 13 |
+
|
| 14 |
+
## Circuit
|
| 15 |
+
|
| 16 |
+
```
|
| 17 |
+
xβ xβ xβ xβ xβ xβ
xβ xβ
|
| 18 |
+
β β β β β β β β
|
| 19 |
+
ββββ΄βββ΄βββ΄βββΌβββ΄βββ΄βββ΄βββ
|
| 20 |
+
βΌ
|
| 21 |
+
βββββββββββ
|
| 22 |
+
β w: -1Γ8 β
|
| 23 |
+
β b: +2 β
|
| 24 |
+
βββββββββββ
|
| 25 |
+
β
|
| 26 |
+
βΌ
|
| 27 |
+
HW β€ 2?
|
| 28 |
+
```
|
| 29 |
+
|
| 30 |
+
## The Double-Error Budget
|
| 31 |
+
|
| 32 |
+
This circuit allows:
|
| 33 |
+
|
| 34 |
+
- Zero active inputs (silence)
|
| 35 |
+
- One active input (single event)
|
| 36 |
+
- Two active inputs (pair/double event)
|
| 37 |
+
|
| 38 |
+
Three or more is considered "too many."
|
| 39 |
+
|
| 40 |
+
## Mechanism
|
| 41 |
+
|
| 42 |
+
```
|
| 43 |
+
sum = -HW + 2
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
| HW | Sum | Output |
|
| 47 |
+
|----|-----|--------|
|
| 48 |
+
| 0 | +2 | 1 |
|
| 49 |
+
| 1 | +1 | 1 |
|
| 50 |
+
| 2 | 0 | 1 |
|
| 51 |
+
| 3 | -1 | 0 |
|
| 52 |
+
| 4+ | < -1 | 0 |
|
| 53 |
+
|
| 54 |
+
The bias of +2 grants a budget of two active inputs.
|
| 55 |
+
|
| 56 |
+
## Error Detection Context
|
| 57 |
+
|
| 58 |
+
In coding theory:
|
| 59 |
+
|
| 60 |
+
- A code with minimum distance d can detect d-1 errors
|
| 61 |
+
- AtMost2 accepts patterns with β€2 bit flips from all-zeros
|
| 62 |
+
- Useful for validating that corruption is within correctable limits
|
| 63 |
+
|
| 64 |
+
| Scenario | This circuit |
|
| 65 |
+
|----------|--------------|
|
| 66 |
+
| No errors | Pass |
|
| 67 |
+
| Single-bit error | Pass |
|
| 68 |
+
| Double-bit error | Pass |
|
| 69 |
+
| Triple+ error | Fail |
|
| 70 |
+
|
| 71 |
+
## Dual of AtLeast6
|
| 72 |
+
|
| 73 |
+
| Circuit | Condition | Sparse/Dense |
|
| 74 |
+
|---------|-----------|--------------|
|
| 75 |
+
| AtLeast6 | HW β₯ 6 | Dense |
|
| 76 |
+
| **AtMost2** | HW β€ 2 | Sparse |
|
| 77 |
+
|
| 78 |
+
Bitwise NOT maps AtMost2 inputs to AtLeast6 inputs.
|
| 79 |
+
|
| 80 |
+
## Coverage
|
| 81 |
+
|
| 82 |
+
| HW | C(8,k) | AtMost2? |
|
| 83 |
+
|----|--------|----------|
|
| 84 |
+
| 0 | 1 | Yes |
|
| 85 |
+
| 1 | 8 | Yes |
|
| 86 |
+
| 2 | 28 | Yes |
|
| 87 |
+
| 3-8 | 219 | No |
|
| 88 |
+
|
| 89 |
+
Fires on 1 + 8 + 28 = **37** of 256 inputs (14.5%).
|
| 90 |
+
|
| 91 |
+
## Parameters
|
| 92 |
+
|
| 93 |
+
| Component | Value |
|
| 94 |
+
|-----------|-------|
|
| 95 |
+
| Weights | all -1 |
|
| 96 |
+
| Bias | +2 |
|
| 97 |
+
| **Total** | **9 parameters** |
|
| 98 |
+
|
| 99 |
+
## Usage
|
| 100 |
+
|
| 101 |
+
```python
|
| 102 |
+
from safetensors.torch import load_file
|
| 103 |
+
import torch
|
| 104 |
+
|
| 105 |
+
w = load_file('model.safetensors')
|
| 106 |
+
|
| 107 |
+
def atmost2(bits):
|
| 108 |
+
inp = torch.tensor([float(b) for b in bits])
|
| 109 |
+
return int((inp * w['weight']).sum() + w['bias'] >= 0)
|
| 110 |
+
|
| 111 |
+
# Double event: allowed
|
| 112 |
+
print(atmost2([1,0,0,0,1,0,0,0])) # 1
|
| 113 |
+
|
| 114 |
+
# Triple event: rejected
|
| 115 |
+
print(atmost2([1,0,0,1,1,0,0,0])) # 0
|
| 116 |
+
```
|
| 117 |
+
|
| 118 |
+
## Files
|
| 119 |
+
|
| 120 |
+
```
|
| 121 |
+
threshold-atmost2outof8/
|
| 122 |
+
βββ model.safetensors
|
| 123 |
+
βββ model.py
|
| 124 |
+
βββ config.json
|
| 125 |
+
βββ README.md
|
| 126 |
+
```
|
| 127 |
+
|
| 128 |
+
## License
|
| 129 |
+
|
| 130 |
+
MIT
|
config.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "threshold-atmost2outof8",
|
| 3 |
+
"description": "At-most-2-out-of-8 detector as threshold circuit",
|
| 4 |
+
"inputs": 8,
|
| 5 |
+
"outputs": 1,
|
| 6 |
+
"neurons": 1,
|
| 7 |
+
"layers": 1,
|
| 8 |
+
"parameters": 9
|
| 9 |
+
}
|
model.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from safetensors.torch import load_file
|
| 3 |
+
|
| 4 |
+
def load_model(path='model.safetensors'):
|
| 5 |
+
return load_file(path)
|
| 6 |
+
|
| 7 |
+
def atmost2(bits, weights):
|
| 8 |
+
"""At-most-2-out-of-8: fires when 0, 1, or 2 inputs are active."""
|
| 9 |
+
inp = torch.tensor([float(b) for b in bits])
|
| 10 |
+
return int((inp * weights['weight']).sum() + weights['bias'] >= 0)
|
| 11 |
+
|
| 12 |
+
if __name__ == '__main__':
|
| 13 |
+
w = load_model()
|
| 14 |
+
print('AtMost2OutOf8 truth table:')
|
| 15 |
+
for hw in range(9):
|
| 16 |
+
bits = [1]*hw + [0]*(8-hw)
|
| 17 |
+
result = atmost2(bits, w)
|
| 18 |
+
print(f'HW={hw}: {result}')
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d0f31cb8e47c2c4efedd3551f5df6d3bc3ff16bf73ec97e7ccdbea9e67b0c071
|
| 3 |
+
size 164
|