File size: 1,175 Bytes
5ce1fb7 |
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 |
---
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
|