Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
•
248 items
•
Updated
•
1
Check if 4-bit input equals 1 (binary 0001).
isone4(a3, a2, a1, a0) = 1 if input == 1, else 0
Where input = 8a3 + 4a2 + 2*a1 + a0
| a3 | a2 | a1 | a0 | decimal | out |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 1 | 1 | 1 |
| 0 | 0 | 1 | 0 | 2 | 0 |
| 0 | 0 | 1 | 1 | 3 | 0 |
| ... | ... | ... | ... | ... | 0 |
Single neuron pattern matcher for binary 0001:
Fires when: -a3 - a2 - a1 + a0 - 1 >= 0
This requires a3=0, a2=0, a1=0, a0=1 (exactly the pattern 0001).
| Inputs | 4 |
| Outputs | 1 |
| Neurons | 1 |
| Layers | 1 |
| Parameters | 5 |
| Magnitude | 5 |
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
def isone4(a3, a2, a1, a0):
inp = torch.tensor([float(a3), float(a2), float(a1), float(a0)])
return int((inp @ w['neuron.weight'].T + w['neuron.bias'] >= 0).item())
print(isone4(0, 0, 0, 1)) # 1 (input = 1)
print(isone4(0, 0, 1, 0)) # 0 (input = 2)
print(isone4(0, 0, 0, 0)) # 0 (input = 0)
MIT