Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
β’
248 items
β’
Updated
β’
1
4-input Winner-Take-All network. A single active input "wins" and produces output. Ties produce no winner.
xβ xβ xβ xβ
β β β β
βββββββββΌββββββββΌββββββββ€
β β β β
βΌ βΌ βΌ βΌ
ββββββββββββββββββββββββββββββββ
β yβ ββ yβ ββ yβ ββ yβ β
β+1 -1 ββ-1 +1 ββ-1 -1 ββ-1 -1 β
β-1 -1 ββ-1 -1 ββ+1 -1 ββ-1 +1 β
βb: -1 ββb: -1 ββb: -1 ββb: -1 β
ββββββββββββββββββββββββββββββββ
β β β β
βΌ βΌ βΌ βΌ
yβ yβ yβ yβ
Each output neuron has:
This creates competition: each neuron tries to fire, but activity from others suppresses it.
| Inputs | Outputs | Interpretation |
|---|---|---|
| 0000 | 0000 | No input, no winner |
| 1000 | 1000 | xβ wins |
| 0100 | 0100 | xβ wins |
| 0010 | 0010 | xβ wins |
| 0001 | 0001 | xβ wins |
| 1100 | 0000 | Tie - no winner |
| 1010 | 0000 | Tie - no winner |
| 1111 | 0000 | All active - no winner |
For yβ to fire:
sum = (+1)Β·xβ + (-1)Β·xβ + (-1)Β·xβ + (-1)Β·xβ - 1
= xβ - xβ - xβ - xβ - 1
This fires only when xβ=1 and all others=0:
WTA is equivalent to "Exactly-1-of-4 with position encoding":
| HW | WTA Output |
|---|---|
| 0 | 0000 |
| 1 | One-hot (winner) |
| 2+ | 0000 (tie) |
This mimics lateral inhibition in neural circuits:
4 neurons, 20 parameters, 1 layer
All neurons compute in parallel. No recurrence needed for binary inputs.
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
def wta(inputs):
inp = torch.tensor([float(x) for x in inputs])
return [int((inp * w[f'y{i}.weight']).sum() + w[f'y{i}.bias'] >= 0)
for i in range(4)]
print(wta([0,1,0,0])) # [0, 1, 0, 0] - x1 wins
print(wta([1,1,0,0])) # [0, 0, 0, 0] - tie
threshold-winnertakeall/
βββ model.safetensors
βββ model.py
βββ config.json
βββ README.md
MIT