File size: 1,603 Bytes
9c4af73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---

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


# threshold-2outof8

At-least-two detector for 8 inputs. Fires when 2 or more bits are set.

## Circuit

```

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

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

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

               β–Ό

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

          β”‚ w: all 1β”‚

          β”‚ b:  -2  β”‚

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

               β”‚

               β–Ό

            HW β‰₯ 2

```

## Mechanism

- Sum = (number of 1s) - 2
- Fires when Hamming weight β‰₯ 2

A single active input isn't enough. Needs corroboration from at least one other.

## k-out-of-8 Family

| Circuit | Bias | Fires when |
|---------|------|------------|
| 1-out-of-8 | -1 | HW β‰₯ 1 |
| **2-out-of-8** | **-2** | **HW β‰₯ 2 (this)** |
| 3-out-of-8 | -3 | HW β‰₯ 3 |
| ... | ... | ... |

All share weights [1,1,1,1,1,1,1,1]. Only the bias differs.

## Parameters

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

## Usage

```python

from safetensors.torch import load_file

import torch



w = load_file('model.safetensors')



def at_least_2(bits):

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

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

```

## Files

```

threshold-2outof8/

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

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

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

└── README.md

```

## License

MIT