metadata
license: mit
tags:
- pytorch
- safetensors
- threshold-logic
- neuromorphic
threshold-atmost3outof8
At-most-3-out-of-8 detector. Fires when three or fewer inputs are active. Identical to Minority.
Circuit
xβ xβ xβ xβ xβ xβ
xβ xβ
β β β β β β β β
ββββ΄βββ΄βββ΄βββΌβββ΄βββ΄βββ΄βββ
βΌ
βββββββββββ
β w: -1Γ8 β
β b: +3 β
βββββββββββ
β
βΌ
HW β€ 3?
Equivalence to Minority
This circuit is functionally identical to threshold-minority:
| Circuit | Condition | Implementation |
|---|---|---|
| Minority | HW β€ 3 | w: all -1, b: +3 |
| AtMost3 | HW β€ 3 | w: all -1, b: +3 |
Both detect "strictly fewer than half." The naming differs by framing:
- "Minority" emphasizes the voting interpretation
- "AtMost3" emphasizes the counting bound
The Tie Boundary
| HW | AtMost3 | Interpretation |
|---|---|---|
| 0-3 | 1 | Minority (< 50%) |
| 4 | 0 | Tie (= 50%) |
| 5-8 | 0 | Majority (> 50%) |
AtMost3 excludes ties. Four active inputs is not "at most 3."
Dual of AtLeast5 (Majority)
| Circuit | Condition | Meaning |
|---|---|---|
| AtLeast5 | HW β₯ 5 | Majority |
| AtMost3 | HW β€ 3 | Minority |
These are not complements - the tie zone (HW = 4) belongs to neither.
Coverage
| HW | C(8,k) | AtMost3? |
|---|---|---|
| 0 | 1 | Yes |
| 1 | 8 | Yes |
| 2 | 28 | Yes |
| 3 | 56 | Yes |
| 4-8 | 163 | No |
Fires on 1 + 8 + 28 + 56 = 93 of 256 inputs (36.3%).
Parameters
| Component | Value |
|---|---|
| Weights | all -1 |
| Bias | +3 |
| Total | 9 parameters |
Usage
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
def atmost3(bits):
inp = torch.tensor([float(b) for b in bits])
return int((inp * w['weight']).sum() + w['bias'] >= 0)
# Three active: minority
print(atmost3([1,1,1,0,0,0,0,0])) # 1
# Four active: tie, not minority
print(atmost3([1,1,1,1,0,0,0,0])) # 0
Files
threshold-atmost3outof8/
βββ model.safetensors
βββ model.py
βββ config.json
βββ README.md
License
MIT