File size: 1,502 Bytes
38de0ac |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
---
license: mit
tags:
- pytorch
- safetensors
- threshold-logic
- neuromorphic
- modular-arithmetic
---
# threshold-mod9
Trivial case: computes Hamming weight mod 9 for 8-bit inputs. Since max HW is 8 < 9, this is just HW.
## Circuit
```
xβ xβ xβ xβ xβ xβ
xβ xβ
β β β β β β β β
β β β β β β β β
w: 1 1 1 1 1 1 1 1
ββββ΄βββ΄βββ΄βββΌβββ΄βββ΄βββ΄βββ
βΌ
βββββββββββ
β b: 0 β
βββββββββββ
β
βΌ
HW (= HW mod 9)
```
## Why Trivial?
For mod m where m > (number of inputs), no reset ever occurs:
- 8 inputs β max HW = 8
- 8 mod 9 = 8 (no wraparound)
The circuit just sums the inputs. It's a degenerate case included for completeness of the MOD-m family.
## Parameters
| | |
|---|---|
| Weights | [1, 1, 1, 1, 1, 1, 1, 1] |
| Bias | 0 |
| Total | 9 parameters |
## Usage
```python
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
def mod9(bits): # Actually just HW
inputs = torch.tensor([float(b) for b in bits])
return int((inputs * w['weight']).sum() + w['bias'])
```
## Files
```
threshold-mod9/
βββ model.safetensors
βββ model.py
βββ config.json
βββ README.md
```
## License
MIT
|