threshold-exactly3outof4

Exactly 3 of 4 inputs high.

Function

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

Truth Table

a b c d sum out
0 0 0 0 0 0
0 0 0 1 1 0
0 0 1 1 2 0
0 1 1 1 3 1
1 0 1 1 3 1
1 1 0 1 3 1
1 1 1 0 3 1
1 1 1 1 4 0

Architecture

Layer 1:
  N1: [1,1,1,1] b=-3  (fires when sum >= 3)
  N2: [-1,-1,-1,-1] b=3  (fires when sum <= 3)

Layer 2:
  AND: [1,1] b=-2  (fires when both N1 and N2 fire)

Parameters

Inputs 4
Outputs 1
Neurons 3
Layers 2
Parameters 13
Magnitude 18

Usage

from safetensors.torch import load_file
import torch

w = load_file('model.safetensors')

def exactly3of4(a, b, c, d):
    inp = torch.tensor([float(a), float(b), float(c), float(d)])
    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(exactly3of4(0, 1, 1, 1))  # 1
print(exactly3of4(1, 1, 1, 1))  # 0

License

MIT

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

Collection including phanerozoic/threshold-exactly3outof4