File size: 1,891 Bytes
0910cb4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
90
91
92
93
94
---
license: mit
tags:
- pytorch
- safetensors
- threshold-logic
- neuromorphic
- weighted-voting
---

# threshold-weighted

Weighted threshold function demonstrating non-uniform input weights.

## Function

y = 1 iff 4·x3 + 3·x2 + 2·x1 + 1·x0 >= 6

Each input has a different "voting power":
- x3: weight 4 (most influential)
- x2: weight 3
- x1: weight 2
- x0: weight 1 (least influential)

Maximum weighted sum = 10, threshold = 6 (weighted majority).

## Truth Table (selected rows)

| x3 | x2 | x1 | x0 | w_sum | y |
|----|----|----|-----|-------|---|
| 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 1 | 6 | **1** |
| 1 | 0 | 0 | 0 | 4 | 0 |
| 1 | 0 | 1 | 0 | 6 | **1** |
| 1 | 1 | 0 | 0 | 7 | **1** |
| 1 | 1 | 1 | 1 | 10 | **1** |

Note: x3 alone (weight 4) isn't enough, but x3 + x1 (weight 6) passes.

## Architecture

Single threshold neuron:

```
x3 ──(×4)──┐
x2 ──(×3)──┼──► Σ ──► (≥6?) ──► y
x1 ──(×2)──┤
x0 ──(×1)──┘
```

## Parameters

| | |
|---|---|
| Inputs | 4 |
| Outputs | 1 |
| Neurons | 1 |
| Layers | 1 |
| Parameters | 5 |
| Magnitude | 16 |

## Theory

This is the fundamental building block of threshold logic. Any linearly separable Boolean function can be computed by a single weighted threshold neuron. Non-linearly-separable functions (like XOR) require multiple layers.

The general form: y = 1 iff Σ(wi·xi) >= θ

## Applications

- Weighted voting systems
- Credit scoring
- Risk assessment
- Neural network layers

## Usage

```python
from safetensors.torch import load_file
import torch

w = load_file('model.safetensors')

def weighted(x3, x2, x1, x0):
    inp = torch.tensor([float(x3), float(x2), float(x1), float(x0)])
    return int((inp @ w['y.weight'].T + w['y.bias'] >= 0).item())

# weighted(1, 0, 1, 0) = 1  # 4+2=6 >= 6
# weighted(1, 0, 0, 1) = 0  # 4+1=5 < 6
```

## License

MIT