Downloads · 30 days
11
22% of all-time downloads
phanerozoic/threshold-demux4
threshold-demux4 is a machine learning model from phanerozoic. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as mit.
1:4 demultiplexer. Routes data input to one of 4 outputs based on 2-bit select.
Downloads · 30 days
11
22% of all-time downloads
All-time downloads
49
Public
Parameters
16
Likes
0
Public
Click a slice to open those files.
.py2.2 KB · 50%
From the Hugging Face model README
1:4 demultiplexer. Routes data input to one of 4 outputs based on 2-bit select.
DEMUX4(d, s1, s0) -> [y0, y1, y2, y3]
yi = d AND (s == i), where s = 2*s1 + s0
| 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 |
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 |
| Inputs | 3 (1 data + 2 select) |
| Outputs | 4 |
| Neurons | 4 |
| Layers | 1 |
| Parameters | 16 |
| Magnitude | 20 |
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]
MIT