Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
•
269 items
•
Updated
•
1
At-least-2-of-6 threshold gate. Fires when 2 or more of the 6 inputs are high.
2outof6(x0, x1, x2, x3, x4, x5) = 1 if (x0 + x1 + x2 + x3 + x4 + x5) >= 2
| Hamming Weight | Output |
|---|---|
| 0 | 0 |
| 1 | 0 |
| 2 | 1 |
| 3 | 1 |
| 4 | 1 |
| 5 | 1 |
| 6 | 1 |
Single threshold neuron with uniform weights. The bias of -2 sets the firing threshold:
| Circuit | Bias | Fires when |
|---|---|---|
| 1-out-of-6 | -1 | HW >= 1 |
| 2-out-of-6 | -2 | HW >= 2 |
| 3-out-of-6 | -3 | HW >= 3 (majority) |
| 4-out-of-6 | -4 | HW >= 4 |
| 5-out-of-6 | -5 | HW >= 5 |
| 6-out-of-6 | -6 | HW = 6 (AND) |
| Weights | [1, 1, 1, 1, 1, 1] |
| Bias | -2 |
| Inputs | 6 |
| Outputs | 1 |
| Neurons | 1 |
| Layers | 1 |
| Parameters | 7 |
| Magnitude | 8 |
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
def at_least_2_of_6(bits):
inputs = torch.tensor([float(b) for b in bits])
return int((inputs @ w['neuron.weight'].T + w['neuron.bias'] >= 0).item())
print(at_least_2_of_6([1, 1, 0, 0, 0, 0])) # 1
MIT