At-most-2-out-of-8 detector. Fires when two or fewer inputs are active. The error-tolerance bound.
x₀ x₁ x₂ x₃ x₄ x₅ x₆ x₇
│ │ │ │ │ │ │ │
└──┴──┴──┴──┼──┴──┴──┴──┘
▼
┌─────────┐
│ w: -1×8 │
│ b: +2 │
└─────────┘
│
▼
HW ≤ 2?
The bias of +2 grants a budget of two active inputs.
Bitwise NOT maps AtMost2 inputs to AtLeast6 inputs.
1from safetensors.torch import load_file
2import torch
3
4w = load_file('model.safetensors')
5
6def atmost2(bits):
7 inp = torch.tensor([float(b) for b in bits])
8 return int((inp * w['weight']).sum() + w['bias'] >= 0)
9
10# Double event: allowed
11print(atmost2([1,0,0,0,1,0,0,0])) # 1
12
13# Triple event: rejected
14print(atmost2([1,0,0,1,1,0,0,0])) # 0
threshold-atmost2outof8/
├── model.safetensors
├── model.py
├── config.json
└── README.md