At-most-3-out-of-8 detector. Fires when three or fewer inputs are active. Identical to Minority.
x₀ x₁ x₂ x₃ x₄ x₅ x₆ x₇
│ │ │ │ │ │ │ │
└──┴──┴──┴──┼──┴──┴──┴──┘
▼
┌─────────┐
│ w: -1×8 │
│ b: +3 │
└─────────┘
│
▼
HW ≤ 3?
AtMost3 excludes ties. Four active inputs is not "at most 3."
These are not complements - the tie zone (HW = 4) belongs to neither.
1from safetensors.torch import load_file
2import torch
3
4w = load_file('model.safetensors')
5
6def atmost3(bits):
7 inp = torch.tensor([float(b) for b in bits])
8 return int((inp * w['weight']).sum() + w['bias'] >= 0)
9
10# Three active: minority
11print(atmost3([1,1,1,0,0,0,0,0])) # 1
12
13# Four active: tie, not minority
14print(atmost3([1,1,1,1,0,0,0,0])) # 0
threshold-atmost3outof8/
├── model.safetensors
├── model.py
├── config.json
└── README.md