File size: 2,005 Bytes
5dd640d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
818e32c
 
 
 
5dd640d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
---

license: mit
tags:
- pytorch
- safetensors
- threshold-logic
- neuromorphic
---


# threshold-majority

Strict majority detector for 8 inputs. Fires when more than half are active.

## Circuit

```

  xβ‚€ x₁ xβ‚‚ x₃ xβ‚„ xβ‚… x₆ x₇

   β”‚  β”‚  β”‚  β”‚  β”‚  β”‚  β”‚  β”‚

   β””β”€β”€β”΄β”€β”€β”΄β”€β”€β”΄β”€β”€β”Όβ”€β”€β”΄β”€β”€β”΄β”€β”€β”΄β”€β”€β”˜

               β–Ό

          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”

          β”‚ w: all 1β”‚

          β”‚ b:  -5  β”‚

          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

               β”‚

               β–Ό

           HW β‰₯ 5?

```

## Mechanism

- Sum = (number of 1s) - 5
- Fires when Hamming weight β‰₯ 5 (more 1s than 0s)

A tie (4-4) doesn't count as majority. You need strictly more than half.

Functionally identical to threshold-5outof8.

## Duality with Minority

| Circuit | Weights | Bias | Fires when |
|---------|---------|------|------------|
| **Majority** | all +1 | -5 | HW β‰₯ 5 |
| Minority | all -1 | +3 | HW ≀ 3 |

Majority: "enough votes to pass"
Minority: "not enough votes to block"

These are not complements (they don't sum to 1). The gap at HW=4 belongs to neither.

## Parameters

| | |
|---|---|
| Weights | [1, 1, 1, 1, 1, 1, 1, 1] |
| Bias | -5 |
| Total | 9 parameters |

## Optimality

Exhaustive enumeration of all 27,298,155 weight configurations at magnitudes 0-13 confirms this circuit is **already at minimum magnitude (13)**. There is exactly one valid configuration at magnitude 13, and no valid configurations exist below it.

## Usage

```python

from safetensors.torch import load_file

import torch



w = load_file('model.safetensors')



def majority(bits):

    inputs = torch.tensor([float(b) for b in bits])

    return int((inputs * w['weight']).sum() + w['bias'] >= 0)

```

## Files

```

threshold-majority/

β”œβ”€β”€ model.safetensors

β”œβ”€β”€ model.py

β”œβ”€β”€ config.json

└── README.md

```

## License

MIT