Upload folder using huggingface_hub
Browse files- README.md +57 -0
- config.json +9 -0
- model.py +23 -0
- model.safetensors +3 -0
README.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
tags:
|
| 4 |
+
- pytorch
|
| 5 |
+
- safetensors
|
| 6 |
+
- threshold-logic
|
| 7 |
+
- neuromorphic
|
| 8 |
+
---
|
| 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 |
+
|
| 16 |
+
```
|
| 17 |
+
xβ xβ xβ xβ xβ xβ
xβ xβ
|
| 18 |
+
β β β β β β β β
|
| 19 |
+
ββββ΄βββ΄βββ΄βββΌβββ΄βββ΄βββ΄βββ
|
| 20 |
+
β
|
| 21 |
+
βββββββββ΄ββββββββ
|
| 22 |
+
βΌ βΌ
|
| 23 |
+
βββββββββββ βββββββββββ
|
| 24 |
+
β AtLeast4β β AtMost4 β
|
| 25 |
+
β w: +1Γ8 β β w: -1Γ8 β
|
| 26 |
+
β b: -4 β β b: +4 β
|
| 27 |
+
βββββββββββ βββββββββββ
|
| 28 |
+
β β
|
| 29 |
+
βββββββββ¬ββββββββ
|
| 30 |
+
βΌ
|
| 31 |
+
βββββββββββ
|
| 32 |
+
β AND β
|
| 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 |
+
|
| 57 |
+
MIT
|
config.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "threshold-exactly4outof8",
|
| 3 |
+
"description": "Exactly-4-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:91807226a6d997a3c1cf1aa33612281e890849d93f61ad1d221b8bb7a1174129
|
| 3 |
+
size 484
|