| | ---
|
| | license: mit
|
| | tags:
|
| | - pytorch
|
| | - safetensors
|
| | - threshold-logic
|
| | - neuromorphic
|
| | ---
|
| |
|
| | # threshold-mux
|
| |
|
| | 2:1 multiplexer. Selects between two inputs based on a select signal.
|
| |
|
| | ## Circuit
|
| |
|
| | ```
|
| | a b s
|
| | β β β
|
| | β βββββΌββββ
|
| | βββββ¬ββββ β
|
| | β βββββ
|
| | βΌ βΌ
|
| | βββββββββββββββ
|
| | β a AND Β¬s β N1: w=[1,0,-1] b=-1
|
| | βββββββββββββββ
|
| | β
|
| | β βββββββββββββββ
|
| | β β b AND s β N2: w=[0,1,1] b=-2
|
| | β βββββββββββββββ
|
| | β β
|
| | ββββββ¬βββββ
|
| | βΌ
|
| | βββββββββββ
|
| | β OR β w=[1,1] b=-1
|
| | βββββββββββ
|
| | β
|
| | βΌ
|
| | output
|
| | ```
|
| |
|
| | ## Function
|
| |
|
| | MUX(a, b, s) = a if s=0, b if s=1
|
| |
|
| | Equivalent to: OR(AND(a, NOT(s)), AND(b, s))
|
| |
|
| | ## Truth Table
|
| |
|
| | | a | b | s | out |
|
| | |---|---|---|-----|
|
| | | 0 | 0 | 0 | 0 |
|
| | | 0 | 0 | 1 | 0 |
|
| | | 0 | 1 | 0 | 0 |
|
| | | 0 | 1 | 1 | 1 |
|
| | | 1 | 0 | 0 | 1 |
|
| | | 1 | 0 | 1 | 0 |
|
| | | 1 | 1 | 0 | 1 |
|
| | | 1 | 1 | 1 | 1 |
|
| |
|
| | ## Architecture
|
| |
|
| | | Layer | Neurons | Weights | Bias |
|
| | |-------|---------|---------|------|
|
| | | 1 | N1 (a AND Β¬s) | [1, 0, -1] | -1 |
|
| | | 1 | N2 (b AND s) | [0, 1, 1] | -2 |
|
| | | 2 | OR | [1, 1] | -1 |
|
| |
|
| | **Total: 3 neurons, 11 parameters, 2 layers**
|
| |
|
| | ## Usage
|
| |
|
| | ```python
|
| | from safetensors.torch import load_file
|
| | import torch
|
| |
|
| | w = load_file('model.safetensors')
|
| |
|
| | def mux(a, b, s):
|
| | inp = torch.tensor([float(a), float(b), float(s)])
|
| | 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())
|
| |
|
| | print(mux(1, 0, 0)) # 1 (selects a)
|
| | print(mux(1, 0, 1)) # 0 (selects b)
|
| | ```
|
| |
|
| | ## Files
|
| |
|
| | ```
|
| | threshold-mux/
|
| | βββ model.safetensors
|
| | βββ model.py
|
| | βββ config.json
|
| | βββ README.md
|
| | ```
|
| |
|
| | ## License
|
| |
|
| | MIT
|
| |
|