File size: 1,222 Bytes
67df09a |
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 |
---
license: mit
tags:
- pytorch
- safetensors
- threshold-logic
- neuromorphic
---
# threshold-2to4decoder
2-to-4 binary decoder. Converts 2-bit input to one-hot 4-bit output.
## Function
decode(A1, A0) -> [Y0, Y1, Y2, Y3]
Yi = 1 iff input = i
## Truth Table
| A1 | A0 | Y0 | Y1 | Y2 | Y3 |
|----|----|----|----|----|-----|
| 0 | 0 | 1 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 | 0 | 0 |
| 1 | 0 | 0 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 | 0 | 1 |
## Architecture
Single layer with 4 neurons. Each Yi matches pattern i.
| Output | Weights [A1, A0] | Bias |
|--------|------------------|------|
| Y0 | [-1, -1] | 0 |
| Y1 | [-1, +1] | -1 |
| Y2 | [+1, -1] | -1 |
| Y3 | [+1, +1] | -2 |
## Parameters
| | |
|---|---|
| Inputs | 2 |
| Outputs | 4 |
| Neurons | 4 |
| Layers | 1 |
| Parameters | 12 |
| Magnitude | 12 |
## Usage
```python
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
def decode2to4(a1, a0):
inp = torch.tensor([float(a1), float(a0)])
return [int((inp * w[f'y{i}.weight']).sum() + w[f'y{i}.bias'] >= 0) for i in range(4)]
print(decode2to4(1, 0)) # [0, 0, 1, 0] - input 2
```
## License
MIT
|