threshold-mux4 / README.md
CharlesCNorton
4:1 multiplexer
8f2cafd
---
license: mit
tags:
- pytorch
- safetensors
- threshold-logic
- neuromorphic
- multiplexer
---
# threshold-mux4
4:1 multiplexer as threshold circuit. Selects one of four data inputs based on 2-bit select signal.
## Circuit
```
d0 ──┐
d1 ──┼──► MUX4 ──► out
d2 ─── β–²
d3 β”€β”€β”˜ β”‚
s1 s0
```
## Truth Table
| s1 | s0 | out |
|----|----|----|
| 0 | 0 | d0 |
| 0 | 1 | d1 |
| 1 | 0 | d2 |
| 1 | 1 | d3 |
## Architecture
| Layer | Neurons | Function |
|-------|---------|----------|
| 1 | 4 | Select gates (one per input) |
| 2 | 1 | OR (combine selections) |
**Total: 5 neurons, 39 parameters, 2 layers**
Each select gate fires only when:
1. Its data input is 1, AND
2. The select lines match its index
## Usage
```python
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
def mux4(d0, d1, d2, d3, s1, s0):
inp = torch.tensor([float(d0), float(d1), float(d2), float(d3),
float(s1), float(s0)])
l1 = (inp @ w['layer1.weight'].T + w['layer1.bias'] >= 0).float()
out = (l1 @ w['layer2.weight'].T + w['layer2.bias'] >= 0).float()
return int(out.item())
```
## Files
```
threshold-mux4/
β”œβ”€β”€ model.safetensors
β”œβ”€β”€ create_safetensors.py
β”œβ”€β”€ config.json
└── README.md
```
## License
MIT