Skip to content

Commit e9f39e9

Browse files
author
grigory
committed
Add Generalized Fast SCAN decoder
1 parent 2fa4313 commit e9f39e9

File tree

13 files changed

+549
-211
lines changed

13 files changed

+549
-211
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
.idea
66
.python-version
77
.pytest_cache
8+
apak/*
89
firestore/*credentials*
910
src*
1011
tests/_trial_temp*

check.ipynb

Lines changed: 0 additions & 91 deletions
This file was deleted.

e_g_fast_ssc_analisys.ipynb

Lines changed: 0 additions & 118 deletions
This file was deleted.

python_polar_coding/polar_codes/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from .fast_scan import FastSCANCodec
22
from .fast_ssc import FastSSCPolarCodec
3+
from .g_fast_scan import GFastSCANCodec
34
from .g_fast_ssc import GeneralizedFastSSCPolarCodec
45
from .rc_scan import RCSCANPolarCodec
56
from .sc import SCPolarCodec
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from .codec import *
2+
from .decoder import *
3+
from .functions import *
4+
from .node import *
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from typing import Union
2+
3+
from python_polar_coding.polar_codes.rc_scan import RCSCANPolarCodec
4+
5+
from .decoder import GFastSCANDecoder
6+
7+
8+
class GFastSCANCodec(RCSCANPolarCodec):
9+
decoder_class = GFastSCANDecoder
10+
11+
def __init__(
12+
self,
13+
N: int,
14+
K: int,
15+
design_snr: float = 0.0,
16+
mask: Union[str, None] = None,
17+
pcc_method: str = RCSCANPolarCodec.BHATTACHARYYA,
18+
AF: int = 1,
19+
I: int = 1,
20+
):
21+
22+
self.AF = AF
23+
super().__init__(N=N, K=K,
24+
design_snr=design_snr,
25+
mask=mask,
26+
pcc_method=pcc_method,
27+
I=I,)
28+
29+
def init_decoder(self):
30+
return self.decoder_class(n=self.n,
31+
mask=self.mask,
32+
AF=self.AF,
33+
I=self.I)
34+
35+
def to_dict(self):
36+
d = super().to_dict()
37+
d.update({'AF': self.AF})
38+
return d
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import numpy as np
2+
3+
from ..rc_scan import RCSCANDecoder
4+
from .node import GFastSCANNode
5+
6+
7+
class GFastSCANDecoder(RCSCANDecoder):
8+
9+
node_class = GFastSCANNode
10+
11+
def __init__(
12+
self,
13+
n: int,
14+
mask: np.array,
15+
AF: int = 1,
16+
I: int = 1,
17+
):
18+
self.AF = AF
19+
super().__init__(n=n, mask=mask, I=I)
20+
21+
def setup_decoding_tree(self, N_min, **kwargs):
22+
"""Setup decoding tree."""
23+
return self.node_class(mask=self.mask, AF=self.AF)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import numba
2+
import numpy as np
3+
4+
from ..fast_scan import compute_spc_beta
5+
from ..rc_scan import compute_beta_one_node
6+
7+
8+
@numba.njit
9+
def compute_g_repetition(llr, mask_steps, last_chunk_type, N):
10+
"""Compute bits for Generalized Repetition node.
11+
12+
Based on: https://arxiv.org/pdf/1804.09508.pdf, Section III, A.
13+
14+
"""
15+
step = N // mask_steps # step is equal to a chunk size
16+
17+
last_alpha = np.zeros(step)
18+
for i in range(step):
19+
last_alpha[i] = np.sum(np.array([
20+
llr[i + j * step] for j in range(mask_steps)
21+
]))
22+
23+
last_beta = (
24+
compute_beta_one_node(last_alpha) if last_chunk_type == 1
25+
else compute_spc_beta(last_alpha)
26+
)
27+
28+
result = np.zeros(N)
29+
for i in range(0, N, step):
30+
result[i: i + step] = last_beta
31+
32+
return result
33+
34+
35+
@numba.njit
36+
def compute_rg_parity(llr, mask_steps, N):
37+
"""Compute bits for Relaxed Generalized Parity Check node.
38+
39+
Based on: https://arxiv.org/pdf/1804.09508.pdf, Section III, B.
40+
41+
"""
42+
step = N // mask_steps # step is equal to a chunk size
43+
result = np.zeros(N)
44+
45+
for i in range(step):
46+
alpha = np.zeros(mask_steps)
47+
for j in range(mask_steps):
48+
alpha[j] = llr[i + j * step]
49+
50+
beta = compute_spc_beta(alpha)
51+
result[i:N:step] = beta
52+
53+
return result
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from python_polar_coding.polar_codes.fast_scan import (
2+
compute_repetition_beta,
3+
compute_spc_beta,
4+
)
5+
from python_polar_coding.polar_codes.g_fast_ssc import GeneralizedFastSSCNode
6+
from python_polar_coding.polar_codes.rc_scan import (
7+
compute_beta_one_node,
8+
compute_beta_zero_node,
9+
)
10+
11+
from .functions import compute_g_repetition, compute_rg_parity
12+
13+
14+
class GFastSCANNode(GeneralizedFastSSCNode):
15+
16+
def compute_leaf_beta(self):
17+
"""Do nothing for ZERO and ONE nodes.
18+
19+
Unlike SC-based decoders SCAN decoders does not make decisions
20+
in ZERO and ONE leaves.
21+
22+
"""
23+
if self.is_repetition:
24+
self.beta = compute_repetition_beta(self.alpha)
25+
if self.is_parity:
26+
self.beta = compute_spc_beta(self.alpha)
27+
if self.is_g_repetition:
28+
self.beta = compute_g_repetition(
29+
llr=self.alpha,
30+
mask_steps=self.mask_steps,
31+
last_chunk_type=self.last_chunk_type,
32+
N=self.N,
33+
)
34+
if self.is_rg_parity:
35+
self.beta = compute_rg_parity(
36+
llr=self.alpha,
37+
mask_steps=self.mask_steps,
38+
N=self.N,
39+
)
40+
41+
def initialize_leaf_beta(self):
42+
"""Initialize BETA values on tree building.
43+
44+
Initialize ZERO and ONE nodes following to Section III
45+
doi:10.1109/jsac.2014.140515
46+
47+
"""
48+
if not self.is_leaf:
49+
return
50+
51+
if self.is_zero:
52+
self._beta = compute_beta_zero_node(self.alpha)
53+
if self.is_one:
54+
self._beta = compute_beta_one_node(self.alpha)

python_polar_coding/polar_codes/g_fast_ssc/functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from ..fast_ssc import compute_single_parity_check
66

77

8-
# @numba.njit
8+
@numba.njit
99
def compute_g_repetition(llr, mask_steps, last_chunk_type, N):
1010
"""Compute bits for Generalized Repetition node.
1111

0 commit comments

Comments
 (0)