metadata
license: mit
tags:
- pytorch
- safetensors
- threshold-logic
- neuromorphic
- decoder
threshold-4to16decoder
4-to-16 binary decoder. Converts 4-bit binary input to one-hot 16-bit output.
Function
decode(a3, a2, a1, a0) -> [y0..y15] where yi=1 iff input=i
One-Hot Encoding
| Input | a3a2a1a0 | Output |
|---|---|---|
| 0 | 0000 | 1000000000000000 |
| 1 | 0001 | 0100000000000000 |
| 5 | 0101 | 0000010000000000 |
| 10 | 1010 | 0000000000100000 |
| 15 | 1111 | 0000000000000001 |
Architecture
Single layer with 16 neurons. Each neuron yi is a pattern matcher for i:
- Weight +1 for bit positions that should be 1
- Weight -1 for bit positions that should be 0
- Bias = -(number of 1 bits in i)
All neurons run in parallel - no dependencies.
Parameters
| Inputs | 4 |
| Outputs | 16 |
| Neurons | 16 |
| Layers | 1 |
| Parameters | 80 |
| Magnitude | 96 |
Usage
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
def decode_4to16(a3, a2, a1, a0):
inp = torch.tensor([float(a3), float(a2), float(a1), float(a0)])
return [int((inp * w[f'y{i}.weight']).sum() + w[f'y{i}.bias'] >= 0)
for i in range(16)]
# Input 10 -> output 10 is hot
outputs = decode_4to16(1, 0, 1, 0)
print(outputs) # [0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0]
License
MIT