threshold-demux4

1:4 demultiplexer. Routes data input to one of 4 outputs based on 2-bit select.

Function

DEMUX4(d, s1, s0) -> [y0, y1, y2, y3]

yi = d AND (s == i), where s = 2*s1 + s0

Truth Table

d s1 s0 y0 y1 y2 y3
0 0 0 0 0 0 0
0 0 1 0 0 0 0
0 1 0 0 0 0 0
0 1 1 0 0 0 0
1 0 0 1 0 0 0
1 0 1 0 1 0 0
1 1 0 0 0 1 0
1 1 1 0 0 0 1

Architecture

Single layer with 4 neurons. Each output yi fires when d=1 AND select matches i.

Output Weights [d, s1, s0] Bias
y0 [1, -1, -1] -1
y1 [1, -1, +1] -2
y2 [1, +1, -1] -2
y3 [1, +1, +1] -3

Parameters

Inputs 3 (1 data + 2 select)
Outputs 4
Neurons 4
Layers 1
Parameters 16
Magnitude 20

Usage

from safetensors.torch import load_file
import torch

w = load_file('model.safetensors')

def demux4(d, s1, s0):
    inp = torch.tensor([float(d), float(s1), float(s0)])
    return [int((inp * w[f'y{i}.weight']).sum() + w[f'y{i}.bias'] >= 0)
            for i in range(4)]

# Route d=1 to output 2 (s=10)
print(demux4(1, 1, 0))  # [0, 0, 1, 0]

License

MIT

Downloads last month
10
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Collection including phanerozoic/threshold-demux4