File size: 1,497 Bytes
a9b8c2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
license: mit
tags:
- pytorch
- safetensors
- threshold-logic
- neuromorphic
---

# threshold-reverse8

8-bit bit reversal. Reverses the order of bits.

## Function

reverse8(a7, a6, a5, a4, a3, a2, a1, a0) = [a0, a1, a2, a3, a4, a5, a6, a7]

## Examples

| Input | Output |
|-------|--------|
| 10000000 | 00000001 |
| 00000001 | 10000000 |
| 10101010 | 01010101 |
| 11110000 | 00001111 |

## Architecture

Single layer with 8 neurons, each copying one input bit to its reversed position.

| Output | Copies from | Weights | Bias |
|--------|-------------|---------|------|
| y0 | a7 | [1,0,0,0,0,0,0,0] | -1 |
| y1 | a6 | [0,1,0,0,0,0,0,0] | -1 |
| y2 | a5 | [0,0,1,0,0,0,0,0] | -1 |
| y3 | a4 | [0,0,0,1,0,0,0,0] | -1 |
| y4 | a3 | [0,0,0,0,1,0,0,0] | -1 |
| y5 | a2 | [0,0,0,0,0,1,0,0] | -1 |
| y6 | a1 | [0,0,0,0,0,0,1,0] | -1 |
| y7 | a0 | [0,0,0,0,0,0,0,1] | -1 |

## Parameters

| | |
|---|---|
| Inputs | 8 |
| Outputs | 8 |
| Neurons | 8 |
| Layers | 1 |
| Parameters | 16 |
| Magnitude | 16 |

## Usage

```python
from safetensors.torch import load_file
import torch

w = load_file('model.safetensors')

def reverse8(a7, a6, a5, a4, a3, a2, a1, a0):
    inp = torch.tensor([float(a7), float(a6), float(a5), float(a4),
                        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 range(8)]

print(reverse8(1, 0, 0, 0, 0, 0, 0, 0))  # [0, 0, 0, 0, 0, 0, 0, 1]
```

## License

MIT