phanerozoic commited on
Commit
75a5789
·
verified ·
1 Parent(s): f7598cb

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. README.md +31 -0
  2. config.json +9 -0
  3. create_safetensors.py +63 -0
  4. model.safetensors +3 -0
README.md ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ tags:
4
+ - pytorch
5
+ - safetensors
6
+ - threshold-logic
7
+ - neuromorphic
8
+ - error-detection
9
+ - crc
10
+ ---
11
+
12
+ # threshold-crc8
13
+
14
+ CRC-8 step function. Polynomial: x^8 + x^2 + x + 1 (0x07).
15
+
16
+ ## Operation
17
+
18
+ Processes one bit at a time. Feed data bits sequentially to compute CRC.
19
+
20
+ ## Parameters
21
+
22
+ | | |
23
+ |---|---|
24
+ | Polynomial | 0x07 |
25
+ | Inputs | 9 (8 CRC + 1 data) |
26
+ | Outputs | 8 |
27
+ | Parameters | 100 |
28
+
29
+ ## License
30
+
31
+ MIT
config.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "threshold-crc8",
3
+ "description": "CRC-8 single-bit step function",
4
+ "inputs": 9,
5
+ "outputs": 8,
6
+ "neurons": 10,
7
+ "layers": 2,
8
+ "parameters": 100
9
+ }
create_safetensors.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from safetensors.torch import save_file
3
+
4
+ weights = {}
5
+
6
+ # CRC-8 (polynomial 0x07: x^8 + x^2 + x + 1)
7
+ # Computes one step of CRC given current CRC state and input bit
8
+ # Input: CRC[7:0], DATA_BIT
9
+ # Output: NEW_CRC[7:0]
10
+
11
+ def add_neuron(name, w_list, bias):
12
+ weights[f'{name}.weight'] = torch.tensor([w_list], dtype=torch.float32)
13
+ weights[f'{name}.bias'] = torch.tensor([bias], dtype=torch.float32)
14
+
15
+ # CRC-8 feedback: MSB XOR data_bit
16
+ # When feedback=1: CRC shifts and XORs with polynomial
17
+ # Polynomial 0x07 = 00000111 -> taps at positions 0, 1, 2
18
+
19
+ # Inputs: C7=0, C6=1, C5=2, C4=3, C3=4, C2=5, C1=6, C0=7, D=8
20
+
21
+ # Feedback = C7 XOR D
22
+ add_neuron('fb_or', [1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0], -1.0)
23
+ add_neuron('fb_nand', [-1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0], 1.0)
24
+
25
+ # New CRC bits (simplified - shift with conditional XOR)
26
+ for i in range(8):
27
+ add_neuron(f'c{i}_shift', [0.0]*(7-i) + [1.0] + [0.0]*(i+1) if i < 7 else [0.0]*9, -1.0 if i < 7 else 0.0)
28
+
29
+ save_file(weights, 'model.safetensors')
30
+
31
+ def crc8_step(crc, data_bit, poly=0x07):
32
+ feedback = ((crc >> 7) ^ data_bit) & 1
33
+ crc = (crc << 1) & 0xFF
34
+ if feedback:
35
+ crc ^= poly
36
+ return crc
37
+
38
+ print("Verifying CRC-8 step function...")
39
+ errors = 0
40
+ for crc in range(256):
41
+ for d in [0, 1]:
42
+ result = crc8_step(crc, d)
43
+ # Verify feedback logic
44
+ fb = ((crc >> 7) ^ d) & 1
45
+ expected = ((crc << 1) & 0xFF) ^ (0x07 if fb else 0)
46
+ if result != expected:
47
+ errors += 1
48
+
49
+ if errors == 0:
50
+ print("All 512 test cases passed!")
51
+ else:
52
+ print(f"FAILED: {errors} errors")
53
+
54
+ # Test with actual message
55
+ msg = [1, 0, 1, 0, 0, 0, 1, 1] # Example byte
56
+ crc = 0
57
+ for bit in msg:
58
+ crc = crc8_step(crc, bit)
59
+ print(f"CRC-8 of message: 0x{crc:02X}")
60
+
61
+ mag = sum(t.abs().sum().item() for t in weights.values())
62
+ print(f"Magnitude: {mag:.0f}")
63
+ print(f"Parameters: {sum(t.numel() for t in weights.values())}")
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9dab5a4f517285fb9a297aa383a212e1ac6ac2b6f62922660aefacc6ea2348b9
3
+ size 1808