threshold-xnor

The equality detector. Fires when both inputs match - both 0 or both 1. Like XOR, this function is not linearly separable and requires two layers.

Circuit

      x       y
      β”‚       β”‚
      β”œβ”€β”€β”€β”¬β”€β”€β”€β”€
      β”‚   β”‚   β”‚
      β–Ό   β”‚   β–Ό
  β”Œβ”€β”€β”€β”€β”€β”€β”β”‚β”Œβ”€β”€β”€β”€β”€β”€β”
  β”‚ NOR  β”‚β”‚β”‚ AND  β”‚   Layer 1
  β”‚w:-1,-1β”‚β”‚w:1,1 β”‚
  β”‚b: 0  β”‚β”‚β”‚b: -2 β”‚
  β””β”€β”€β”€β”€β”€β”€β”˜β”‚β””β”€β”€β”€β”€β”€β”€β”˜
      β”‚   β”‚   β”‚
      β””β”€β”€β”€β”Όβ”€β”€β”€β”˜
          β–Ό
      β”Œβ”€β”€β”€β”€β”€β”€β”
      β”‚  OR  β”‚         Layer 2
      β”‚w: 1,1β”‚
      β”‚b: -1 β”‚
      β””β”€β”€β”€β”€β”€β”€β”˜
          β”‚
          β–Ό
      XNOR(x,y)

Mechanism

XNOR catches equality via two cases:

  • NOR fires when both inputs are 0 (both quiet)
  • AND fires when both inputs are 1 (both active)
  • OR combines: at least one case holds
x y NOR AND OR(NOR,AND)
0 0 1 0 1
0 1 0 0 0
1 0 0 0 0
1 1 0 1 1

XNOR = NOT(XOR). Same non-linear structure, opposite meaning.

Parameters

Layer Weights Bias
NOR [-1, -1] 0
AND [1, 1] -2
OR [1, 1] -1
Total 9

Properties

  • Commutative: XNOR(x,y) = XNOR(y,x)
  • Reflexive: XNOR(x,x) = 1
  • Equality: x = y iff XNOR(x,y) = 1

Usage

from safetensors.torch import load_file
import torch

w = load_file('model.safetensors')

def xnor_gate(x, y):
    inp = torch.tensor([float(x), float(y)])

    nor_out = int((inp * w['layer1.neuron1.weight']).sum() + w['layer1.neuron1.bias'] >= 0)
    and_out = int((inp * w['layer1.neuron2.weight']).sum() + w['layer1.neuron2.bias'] >= 0)

    l1 = torch.tensor([float(nor_out), float(and_out)])
    return int((l1 * w['layer2.weight']).sum() + w['layer2.bias'] >= 0)

Files

threshold-xnor/
β”œβ”€β”€ model.safetensors
β”œβ”€β”€ model.py
β”œβ”€β”€ config.json
└── README.md

License

MIT

Downloads last month
9
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Collection including phanerozoic/threshold-xnor