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
11
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Collection including phanerozoic/threshold-exactly1outof8