threshold-exactly3outof5

Exactly 3 of 5 inputs high.

Function

exactly3outof5(a, b, c, d, e) = 1 if (a + b + c + d + e) == 3, else 0

Truth Table (selected)

sum out
0 0
1 0
2 0
3 1
4 0
5 0

Architecture

Two layers required (exactly-k is not linearly separable).

Layer 1:

  • N1: sum >= 3 (weights [1,1,1,1,1], bias -3)
  • N2: sum <= 3 (weights [-1,-1,-1,-1,-1], bias 3)

Layer 2:

  • AND(N1, N2): weights [1,1], bias -2

Parameters

Inputs 5
Outputs 1
Neurons 3
Layers 2
Parameters 15
Magnitude 20

Usage

from safetensors.torch import load_file
import torch

w = load_file('model.safetensors')

def exactly3of5(a, b, c, d, e):
    inp = torch.tensor([float(a), float(b), float(c), float(d), float(e)])
    l1 = (inp @ w['layer1.weight'].T + w['layer1.bias'] >= 0).float()
    out = (l1 @ w['layer2.weight'].T + w['layer2.bias'] >= 0).float()
    return int(out.item())

print(exactly3of5(1, 1, 1, 0, 0))  # 1 (sum=3)
print(exactly3of5(1, 1, 1, 1, 0))  # 0 (sum=4)

License

MIT

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

Collection including phanerozoic/threshold-exactly3outof5