threshold-exactly1outof8

Exactly-1-out-of-8 detector. Fires when exactly one input is active.

Circuit

  x₀ x₁ x₂ x₃ x₄ x₅ x₆ x₇
   │  │  │  │  │  │  │  │
   └──┴──┴──┴──┼──┴──┴──┴──┘
               │
       ┌───────┴───────┐
       ▼               ▼
  ┌─────────┐     ┌─────────┐
  │ AtLeast1│     │ AtMost1 │
  │ w: +1×8 │     │ w: -1×8 │
  │ b:  -1  │     │ b:  +1  │
  └─────────┘     └─────────┘
       │               │
       └───────┬───────┘
               ▼
          ┌─────────┐
          │   AND   │
          │ w: 1, 1 │
          │ b:  -2  │
          └─────────┘
               │
               ▼
          (HW = 1?)

Mechanism

The circuit uses two threshold neurons in parallel:

  1. AtLeast1: Fires when HW ≥ 1 (at least one input active)

    • Weights: all +1
    • Bias: -1
  2. AtMost1: Fires when HW ≤ 1 (at most one input active)

    • Weights: all -1
    • Bias: +1
    • Logic: fires when -HW + 1 ≥ 0, i.e., HW ≤ 1
  3. AND: Combines the two conditions

    • Exactly1 = AtLeast1 AND AtMost1

Truth Table

HW AtLeast1 AtMost1 Exactly1
0 0 1 0
1 1 1 1
2 1 0 0
3 1 0 0
... 1 0 0
8 1 0 0

Exactly-k Family

Circuit AtLeast bias AtMost bias
Exactly1 -1 +1
Exactly2 -2 +2
Exactly3 -3 +3
... -k +k
Exactly7 -7 +7

All use the same structure: two threshold detectors + AND.

Architecture

Component Neurons Parameters
AtLeast1 1 9
AtMost1 1 9
AND 1 3
Total 3 21

Layers: 2

Usage

from safetensors.torch import load_file
import torch

w = load_file('model.safetensors')

def exactly1(bits):
    inp = torch.tensor([float(b) for b in bits])
    atleast = int((inp * w['atleast.weight']).sum() + w['atleast.bias'] >= 0)
    atmost = int((inp * w['atmost.weight']).sum() + w['atmost.bias'] >= 0)
    return int((torch.tensor([float(atleast), float(atmost)]) * w['and.weight']).sum() + w['and.bias'] >= 0)

bits = [0, 0, 0, 1, 0, 0, 0, 0]  # HW=1
print(exactly1(bits))  # 1

Files

threshold-exactly1outof8/
├── model.safetensors
├── model.py
├── config.json
└── README.md

License

MIT

Downloads last month
1
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Collection including phanerozoic/threshold-exactly1outof8

Free AI Image Generator No sign-up. Instant results. Open Now