Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks. • 269 items • Updated • 1
At-least-three detector. Fires when 3 or more of 8 inputs are set.
x₀ x₁ x₂ x₃ x₄ x₅ x₆ x₇
│ │ │ │ │ │ │ │
└──┴──┴──┴──┼──┴──┴──┴──┘
▼
┌─────────┐
│ w: all 1│
│ b: -3 │
└─────────┘
│
▼
HW ≥ 3
Two active inputs aren't enough. Needs a third to cross threshold.
| Circuit | Bias | Fires when |
|---|---|---|
| 1-out-of-8 | -1 | HW ≥ 1 |
| 2-out-of-8 | -2 | HW ≥ 2 |
| 3-out-of-8 | -3 | HW ≥ 3 (this) |
| 4-out-of-8 | -4 | HW ≥ 4 |
| ... | ... | ... |
| Weights | [1, 1, 1, 1, 1, 1, 1, 1] |
| Bias | -3 |
| Total | 9 parameters |
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
def at_least_3(bits):
inputs = torch.tensor([float(b) for b in bits])
return int((inputs * w['weight']).sum() + w['bias'] >= 0)
threshold-3outof8/
├── model.safetensors
├── model.py
├── config.json
└── README.md
MIT