Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
β’
269 items
β’
Updated
β’
1
At-least-one detector for 6 inputs. Equivalent to a 6-input OR gate. The loosest threshold in the k-out-of-6 family.
x0 x1 x2 x3 x4 x5
β β β β β β
βββββ΄ββββ΄ββββΌββββ΄ββββ΄ββββ
βΌ
βββββββββββ
β w: all 1β
β b: -1 β
βββββββββββ
β
βΌ
HW >= 1
1outof6(x0, x1, x2, x3, x4, x5) = 1 if (x0 + x1 + x2 + x3 + x4 + x5) >= 1
Returns 1 when at least one input is high (Hamming weight >= 1).
| Inputs | HW | Output |
|---|---|---|
| 000000 | 0 | 0 |
| 000001 | 1 | 1 |
| 000010 | 1 | 1 |
| 010101 | 3 | 1 |
| 111111 | 6 | 1 |
Only the all-zeros input produces 0.
With uniform weights of 1 and bias -1, the neuron fires when at least one input is active:
| Circuit | Bias | Fires when |
|---|---|---|
| 1-out-of-6 | -1 | HW >= 1 (this) |
| 2-out-of-6 | -2 | HW >= 2 |
| 3-out-of-6 | -3 | HW >= 3 |
| 4-out-of-6 | -4 | HW >= 4 |
| 5-out-of-6 | -5 | HW >= 5 |
| 6-out-of-6 | -6 | HW = 6 |
All share weights [1,1,1,1,1,1]. Only the bias differs.
| Weights | [1, 1, 1, 1, 1, 1] |
| Bias | -1 |
| Inputs | 6 |
| Outputs | 1 |
| Neurons | 1 |
| Layers | 1 |
| Parameters | 7 |
| Magnitude | 7 |
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
def at_least_1_of_6(bits):
inputs = torch.tensor([float(b) for b in bits])
return int((inputs @ w['neuron.weight'].T + w['neuron.bias'] >= 0).item())
# Examples
print(at_least_1_of_6([0, 0, 0, 0, 0, 0])) # 0
print(at_least_1_of_6([0, 0, 0, 0, 0, 1])) # 1
print(at_least_1_of_6([1, 0, 1, 0, 1, 0])) # 1
threshold-1outof6/
βββ model.safetensors
βββ model.py
βββ create_safetensors.py
βββ config.json
βββ README.md
MIT