Upload folder using huggingface_hub
Browse files- README.md +114 -0
- config.json +9 -0
- model.py +17 -0
- model.safetensors +3 -0
README.md
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
tags:
|
| 4 |
+
- pytorch
|
| 5 |
+
- safetensors
|
| 6 |
+
- threshold-logic
|
| 7 |
+
- neuromorphic
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
# threshold-atmost4outof8
|
| 11 |
+
|
| 12 |
+
At-most-4-out-of-8 detector. Fires when half or fewer inputs are active. The non-majority detector.
|
| 13 |
+
|
| 14 |
+
## Circuit
|
| 15 |
+
|
| 16 |
+
```
|
| 17 |
+
xβ xβ xβ xβ xβ xβ
xβ xβ
|
| 18 |
+
β β β β β β β β
|
| 19 |
+
ββββ΄βββ΄βββ΄βββΌβββ΄βββ΄βββ΄βββ
|
| 20 |
+
βΌ
|
| 21 |
+
βββββββββββ
|
| 22 |
+
β w: -1Γ8 β
|
| 23 |
+
β b: +4 β
|
| 24 |
+
βββββββββββ
|
| 25 |
+
β
|
| 26 |
+
βΌ
|
| 27 |
+
HW β€ 4?
|
| 28 |
+
```
|
| 29 |
+
|
| 30 |
+
## The Majority Complement
|
| 31 |
+
|
| 32 |
+
This is NOT(Majority):
|
| 33 |
+
|
| 34 |
+
| HW | Majority (β₯5) | AtMost4 (β€4) |
|
| 35 |
+
|----|---------------|--------------|
|
| 36 |
+
| 0-4 | 0 | 1 |
|
| 37 |
+
| 5-8 | 1 | 0 |
|
| 38 |
+
|
| 39 |
+
Exactly one fires for any input. They partition the input space.
|
| 40 |
+
|
| 41 |
+
## Includes Ties
|
| 42 |
+
|
| 43 |
+
| HW | AtMost3 | **AtMost4** | AtMost5 |
|
| 44 |
+
|----|---------|-------------|---------|
|
| 45 |
+
| 3 | 1 | 1 | 1 |
|
| 46 |
+
| 4 | 0 | **1** | 1 |
|
| 47 |
+
| 5 | 0 | 0 | 1 |
|
| 48 |
+
|
| 49 |
+
AtMost4 is the first in the family to include the tie case (HW = 4).
|
| 50 |
+
|
| 51 |
+
## Coverage
|
| 52 |
+
|
| 53 |
+
Fires on more than half of all inputs:
|
| 54 |
+
|
| 55 |
+
| HW | C(8,k) | AtMost4? |
|
| 56 |
+
|----|--------|----------|
|
| 57 |
+
| 0 | 1 | Yes |
|
| 58 |
+
| 1 | 8 | Yes |
|
| 59 |
+
| 2 | 28 | Yes |
|
| 60 |
+
| 3 | 56 | Yes |
|
| 61 |
+
| 4 | 70 | Yes |
|
| 62 |
+
| 5-8 | 93 | No |
|
| 63 |
+
|
| 64 |
+
Total: 1 + 8 + 28 + 56 + 70 = **163** of 256 inputs (63.7%).
|
| 65 |
+
|
| 66 |
+
## Dual of AtLeast4
|
| 67 |
+
|
| 68 |
+
| Circuit | Condition | Fires on |
|
| 69 |
+
|---------|-----------|----------|
|
| 70 |
+
| AtLeast4 | HW β₯ 4 | 163 inputs |
|
| 71 |
+
| **AtMost4** | HW β€ 4 | 163 inputs |
|
| 72 |
+
|
| 73 |
+
Both fire on 163 inputs, but different sets. Their intersection is exactly HW = 4 (70 inputs).
|
| 74 |
+
|
| 75 |
+
## Parameters
|
| 76 |
+
|
| 77 |
+
| Component | Value |
|
| 78 |
+
|-----------|-------|
|
| 79 |
+
| Weights | all -1 |
|
| 80 |
+
| Bias | +4 |
|
| 81 |
+
| **Total** | **9 parameters** |
|
| 82 |
+
|
| 83 |
+
## Usage
|
| 84 |
+
|
| 85 |
+
```python
|
| 86 |
+
from safetensors.torch import load_file
|
| 87 |
+
import torch
|
| 88 |
+
|
| 89 |
+
w = load_file('model.safetensors')
|
| 90 |
+
|
| 91 |
+
def atmost4(bits):
|
| 92 |
+
inp = torch.tensor([float(b) for b in bits])
|
| 93 |
+
return int((inp * w['weight']).sum() + w['bias'] >= 0)
|
| 94 |
+
|
| 95 |
+
# Tie (4 active): included
|
| 96 |
+
print(atmost4([1,1,1,1,0,0,0,0])) # 1
|
| 97 |
+
|
| 98 |
+
# Majority (5 active): excluded
|
| 99 |
+
print(atmost4([1,1,1,1,1,0,0,0])) # 0
|
| 100 |
+
```
|
| 101 |
+
|
| 102 |
+
## Files
|
| 103 |
+
|
| 104 |
+
```
|
| 105 |
+
threshold-atmost4outof8/
|
| 106 |
+
βββ model.safetensors
|
| 107 |
+
βββ model.py
|
| 108 |
+
βββ config.json
|
| 109 |
+
βββ README.md
|
| 110 |
+
```
|
| 111 |
+
|
| 112 |
+
## License
|
| 113 |
+
|
| 114 |
+
MIT
|
config.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "threshold-atmost4outof8",
|
| 3 |
+
"description": "At-most-4-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,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 atmost4(bits, weights):
|
| 8 |
+
"""At-most-4-out-of-8: fires when half or fewer 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('AtMost4OutOf8: HW <= 4')
|
| 15 |
+
for hw in range(9):
|
| 16 |
+
bits = [1]*hw + [0]*(8-hw)
|
| 17 |
+
print(f'HW={hw}: {atmost4(bits, w)}')
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a3aa78ce3e02ebb13fec291f4aa80813bc4c28f0525d24885d41cd6448c289b5
|
| 3 |
+
size 164
|