threshold-onehot-decoder

4-to-2 one-hot decoder. Converts a 4-bit one-hot representation to a 2-bit binary value.

Function

onehot_decode(y3, y2, y1, y0) -> (a1, a0)

Input must have exactly one bit set.

Truth Table

y3 y2 y1 y0 a1 a0 Value
0 0 0 1 0 0 0
0 0 1 0 0 1 1
0 1 0 0 1 0 2
1 0 0 0 1 1 3

Architecture

Single-layer implementation:

  y3   y2   y1   y0
   β”‚    β”‚    β”‚    β”‚
   β””β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”˜
         β”‚
    β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”
    β”‚         β”‚
    β–Ό         β–Ό
  β”Œβ”€β”€β”€β”     β”Œβ”€β”€β”€β”
  β”‚a1 β”‚     β”‚a0 β”‚  Layer 1
  β”‚OR β”‚     β”‚OR β”‚
  β””β”€β”€β”€β”˜     β””β”€β”€β”€β”˜
    β”‚         β”‚
    β–Ό         β–Ό

Each output is a single OR gate:

  • a0 = OR(y1, y3): w=[1,0,1,0], b=-1
  • a1 = OR(y2, y3): w=[1,1,0,0], b=-1

The decoder recognizes that:

  • Bit 0 of position = 1 for positions 1 and 3
  • Bit 1 of position = 1 for positions 2 and 3

Parameters

Inputs 4
Outputs 2
Neurons 2
Layers 1
Parameters 10
Magnitude 6

Usage

from safetensors.torch import load_file
import torch

w = load_file('model.safetensors')

def decode(y3, y2, y1, y0):
    inp = torch.tensor([float(y3), float(y2), float(y1), float(y0)])
    a0 = int((inp @ w['a0.weight'].T + w['a0.bias'] >= 0).item())
    a1 = int((inp @ w['a1.weight'].T + w['a1.bias'] >= 0).item())
    return a1, a0

# decode(0, 1, 0, 0) = (1, 0)  # value 2

Applications

  • Priority encoder output processing
  • State machine decoding
  • Memory address reconstruction
  • Neural network output interpretation

License

MIT

Downloads last month
11
Safetensors
Model size
10 params
Tensor type
F32
Β·
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Collection including phanerozoic/threshold-onehot-decoder