Upload folder using huggingface_hub
Browse files- README.md +71 -0
- config.json +9 -0
- model.py +23 -0
- model.safetensors +3 -0
README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
tags:
|
| 4 |
+
- pytorch
|
| 5 |
+
- safetensors
|
| 6 |
+
- threshold-logic
|
| 7 |
+
- neuromorphic
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
# threshold-exactly2outof8
|
| 11 |
+
|
| 12 |
+
Exactly-2-out-of-8 detector. Fires when exactly two inputs are active.
|
| 13 |
+
|
| 14 |
+
## Circuit
|
| 15 |
+
|
| 16 |
+
```
|
| 17 |
+
xβ xβ xβ xβ xβ xβ
xβ xβ
|
| 18 |
+
β β β β β β β β
|
| 19 |
+
ββββ΄βββ΄βββ΄βββΌβββ΄βββ΄βββ΄βββ
|
| 20 |
+
β
|
| 21 |
+
βββββββββ΄ββββββββ
|
| 22 |
+
βΌ βΌ
|
| 23 |
+
βββββββββββ βββββββββββ
|
| 24 |
+
β AtLeast2β β AtMost2 β
|
| 25 |
+
β w: +1Γ8 β β w: -1Γ8 β
|
| 26 |
+
β b: -2 β β b: +2 β
|
| 27 |
+
βββββββββββ βββββββββββ
|
| 28 |
+
β β
|
| 29 |
+
βββββββββ¬ββββββββ
|
| 30 |
+
βΌ
|
| 31 |
+
βββββββββββ
|
| 32 |
+
β AND β
|
| 33 |
+
βββββββββββ
|
| 34 |
+
β
|
| 35 |
+
βΌ
|
| 36 |
+
(HW = 2?)
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
## Mechanism
|
| 40 |
+
|
| 41 |
+
- **AtLeast2**: Fires when HW β₯ 2 (bias -2)
|
| 42 |
+
- **AtMost2**: Fires when HW β€ 2 (weights -1, bias +2)
|
| 43 |
+
- **AND**: Exactly2 = AtLeast2 AND AtMost2
|
| 44 |
+
|
| 45 |
+
## Truth Table
|
| 46 |
+
|
| 47 |
+
| HW | AtLeast2 | AtMost2 | Exactly2 |
|
| 48 |
+
|----|----------|---------|----------|
|
| 49 |
+
| 0 | 0 | 1 | 0 |
|
| 50 |
+
| 1 | 0 | 1 | 0 |
|
| 51 |
+
| 2 | 1 | 1 | **1** |
|
| 52 |
+
| 3 | 1 | 0 | 0 |
|
| 53 |
+
| ... | 1 | 0 | 0 |
|
| 54 |
+
|
| 55 |
+
## Architecture
|
| 56 |
+
|
| 57 |
+
**3 neurons, 21 parameters, 2 layers**
|
| 58 |
+
|
| 59 |
+
## Files
|
| 60 |
+
|
| 61 |
+
```
|
| 62 |
+
threshold-exactly2outof8/
|
| 63 |
+
βββ model.safetensors
|
| 64 |
+
βββ model.py
|
| 65 |
+
βββ config.json
|
| 66 |
+
βββ README.md
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
## License
|
| 70 |
+
|
| 71 |
+
MIT
|
config.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "threshold-exactly2outof8",
|
| 3 |
+
"description": "Exactly-2-out-of-8 detector as threshold circuit",
|
| 4 |
+
"inputs": 8,
|
| 5 |
+
"outputs": 1,
|
| 6 |
+
"neurons": 3,
|
| 7 |
+
"layers": 2,
|
| 8 |
+
"parameters": 21
|
| 9 |
+
}
|
model.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 exactlyK(bits, weights):
|
| 8 |
+
"""Exactly-K-out-of-8 detector.
|
| 9 |
+
bits: list of 8 binary values
|
| 10 |
+
Returns: 1 if exactly K bits are set, 0 otherwise
|
| 11 |
+
"""
|
| 12 |
+
inp = torch.tensor([float(b) for b in bits])
|
| 13 |
+
atleast = int((inp * weights['atleast.weight']).sum() + weights['atleast.bias'] >= 0)
|
| 14 |
+
atmost = int((inp * weights['atmost.weight']).sum() + weights['atmost.bias'] >= 0)
|
| 15 |
+
return int((torch.tensor([float(atleast), float(atmost)]) * weights['and.weight']).sum() + weights['and.bias'] >= 0)
|
| 16 |
+
|
| 17 |
+
if __name__ == '__main__':
|
| 18 |
+
w = load_model()
|
| 19 |
+
print('ExactlyKOutOf8 Detector')
|
| 20 |
+
for hw in range(9):
|
| 21 |
+
bits = [1] * hw + [0] * (8 - hw)
|
| 22 |
+
result = exactlyK(bits, w)
|
| 23 |
+
print(f'HW={hw}: {result}')
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:140924bcb6ff3dd9b269169c5652694c92023c60617169c1a799e3b4ab0baa86
|
| 3 |
+
size 484
|