Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
•
248 items
•
Updated
•
1
Exactly 3 of 5 inputs high.
exactly3outof5(a, b, c, d, e) = 1 if (a + b + c + d + e) == 3, else 0
| sum | out |
|---|---|
| 0 | 0 |
| 1 | 0 |
| 2 | 0 |
| 3 | 1 |
| 4 | 0 |
| 5 | 0 |
Two layers required (exactly-k is not linearly separable).
Layer 1:
Layer 2:
| Inputs | 5 |
| Outputs | 1 |
| Neurons | 3 |
| Layers | 2 |
| Parameters | 15 |
| Magnitude | 20 |
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
def exactly3of5(a, b, c, d, e):
inp = torch.tensor([float(a), float(b), float(c), float(d), float(e)])
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(exactly3of5(1, 1, 1, 0, 0)) # 1 (sum=3)
print(exactly3of5(1, 1, 1, 1, 0)) # 0 (sum=4)
MIT