|
|
--- |
|
|
license: mit |
|
|
tags: |
|
|
- pytorch |
|
|
- safetensors |
|
|
- threshold-logic |
|
|
- neuromorphic |
|
|
--- |
|
|
|
|
|
# threshold-reverse4 |
|
|
|
|
|
4-bit bit reversal. Reverses the order of bits. |
|
|
|
|
|
## Function |
|
|
|
|
|
reverse4(a3, a2, a1, a0) = [a0, a1, a2, a3] |
|
|
|
|
|
| Input | Output | |
|
|
|-------|--------| |
|
|
| 0001 | 1000 | |
|
|
| 1000 | 0001 | |
|
|
| 0110 | 0110 | |
|
|
| 1010 | 0101 | |
|
|
|
|
|
## Architecture |
|
|
|
|
|
Single layer with 4 neurons, each copying one input bit to its reversed position. |
|
|
|
|
|
| Output | Copies from | Weights [a3,a2,a1,a0] | Bias | |
|
|
|--------|-------------|------------------------|------| |
|
|
| y3 | a0 | [0, 0, 0, 1] | -1 | |
|
|
| y2 | a1 | [0, 0, 1, 0] | -1 | |
|
|
| y1 | a2 | [0, 1, 0, 0] | -1 | |
|
|
| y0 | a3 | [1, 0, 0, 0] | -1 | |
|
|
|
|
|
## Parameters |
|
|
|
|
|
| | | |
|
|
|---|---| |
|
|
| Inputs | 4 | |
|
|
| Outputs | 4 | |
|
|
| Neurons | 4 | |
|
|
| Layers | 1 | |
|
|
| Parameters | 8 | |
|
|
| Magnitude | 8 | |
|
|
|
|
|
## Usage |
|
|
|
|
|
```python |
|
|
from safetensors.torch import load_file |
|
|
import torch |
|
|
|
|
|
w = load_file('model.safetensors') |
|
|
|
|
|
def reverse4(a3, a2, a1, a0): |
|
|
inp = torch.tensor([float(a3), float(a2), float(a1), float(a0)]) |
|
|
return [int((inp @ w[f'y{i}.weight'].T + w[f'y{i}.bias'] >= 0).item()) |
|
|
for i in [3, 2, 1, 0]] |
|
|
|
|
|
print(reverse4(1, 0, 0, 0)) # [0, 0, 0, 1] |
|
|
``` |
|
|
|
|
|
## License |
|
|
|
|
|
MIT |
|
|
|