threshold-symmetric-s23

Symmetric function S_2^3: outputs 1 if and only if exactly 2 of 3 inputs are 1.

Function

S_2^3(x2, x1, x0) = 1 iff (x2 + x1 + x0) = 2

Symmetric functions are invariant under input permutation.

Truth Table

x2 x1 x0 sum y
0 0 0 0 0
0 0 1 1 0
0 1 0 1 0
0 1 1 2 1
1 0 0 1 0
1 0 1 2 1
1 1 0 2 1
1 1 1 3 0

Architecture

x2   x1   x0
 β”‚    β”‚    β”‚
 β””β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”˜
      β”‚
 β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”
 β”‚         β”‚
 β–Ό         β–Ό
β”Œβ”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”
β”‚>=2  β”‚  β”‚<=2  β”‚   Layer 1
β””β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”˜
   β”‚        β”‚
   β””β”€β”€β”€β”¬β”€β”€β”€β”€β”˜
       β”‚
       β–Ό
    β”Œβ”€β”€β”€β”€β”€β”
    β”‚ AND β”‚        Layer 2
    β””β”€β”€β”€β”€β”€β”˜
       β”‚
       β–Ό
       y
  • at_least_2: w=[1,1,1], b=-2
  • at_most_2: w=[-1,-1,-1], b=2
  • y = AND(at_least_2, at_most_2)

Parameters

Inputs 3
Outputs 1
Neurons 3
Layers 2
Parameters 11
Magnitude 14

Symmetric Functions

The general symmetric function S_k^n outputs 1 iff exactly k of n inputs are 1. Special cases:

  • S_0^n = NOR (no inputs set)
  • S_n^n = AND (all inputs set)
  • S_1^n to S_{n-1}^n = "exactly k" functions

Usage

from safetensors.torch import load_file
import torch

w = load_file('model.safetensors')

def s23(x2, x1, x0):
    inp = torch.tensor([float(x2), float(x1), float(x0)])
    al2 = int((inp @ w['at_least_2.weight'].T + w['at_least_2.bias'] >= 0).item())
    am2 = int((inp @ w['at_most_2.weight'].T + w['at_most_2.bias'] >= 0).item())
    l1 = torch.tensor([float(al2), float(am2)])
    return int((l1 @ w['y.weight'].T + w['y.bias'] >= 0).item())

# s23(1, 1, 0) = 1  # exactly 2 of 3
# s23(1, 1, 1) = 0  # 3 of 3, not exactly 2

License

MIT

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

Collection including phanerozoic/threshold-symmetric-s23