Skip to content

Commit 2fa4313

Browse files
author
grigory
committed
Add Fast SCAN polar codec
1 parent b83b700 commit 2fa4313

File tree

12 files changed

+287
-7
lines changed

12 files changed

+287
-7
lines changed

python_polar_coding/polar_codes/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from .fast_scan import FastSCANCodec
12
from .fast_ssc import FastSSCPolarCodec
23
from .g_fast_ssc import GeneralizedFastSSCPolarCodec
34
from .rc_scan import RCSCANPolarCodec
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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from python_polar_coding.polar_codes.rc_scan import RCSCANPolarCodec
2+
3+
from .decoder import FastSCANDecoder
4+
5+
6+
class FastSCANCodec(RCSCANPolarCodec):
7+
decoder_class = FastSCANDecoder
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from python_polar_coding.polar_codes.rc_scan import RCSCANDecoder
2+
3+
from .node import FastSCANNode
4+
5+
6+
class FastSCANDecoder(RCSCANDecoder):
7+
node_class = FastSCANNode
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import numba
2+
import numpy as np
3+
4+
5+
@numba.njit
6+
def compute_repetition_beta(alpha) -> np.array:
7+
"""Compute beta value for Repetition node."""
8+
alpha_sum = np.sum(alpha)
9+
return -1 * alpha + alpha_sum
10+
11+
12+
@numba.njit
13+
def compute_spc_beta(alpha) -> np.array:
14+
"""Compute beta value for Single parity node."""
15+
all_sign = np.sign(np.prod(alpha))
16+
abs_alpha = np.fabs(alpha)
17+
first_min_idx, second_min_idx = np.argsort(abs_alpha)[:2]
18+
19+
result = np.sign(alpha) * all_sign
20+
for i in range(result.size):
21+
if i == first_min_idx:
22+
result[i] *= abs_alpha[second_min_idx]
23+
else:
24+
result[i] *= abs_alpha[first_min_idx]
25+
26+
return result
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
from python_polar_coding.polar_codes.rc_scan import (
2+
RCSCANNode,
3+
compute_beta_one_node,
4+
compute_beta_zero_node,
5+
)
6+
7+
from .functions import compute_repetition_beta, compute_spc_beta
8+
9+
10+
class FastSCANNode(RCSCANNode):
11+
12+
def compute_leaf_beta(self):
13+
"""Compute leaf beta."""
14+
if self.is_repetition:
15+
self.beta = compute_repetition_beta(self.alpha)
16+
if self.is_parity:
17+
self.beta = compute_spc_beta(self.alpha)
18+
19+
def initialize_leaf_beta(self):
20+
"""Initialize BETA values on tree building.
21+
22+
Initialize ZERO and ONE nodes following to Section III
23+
doi:10.1109/jsac.2014.140515
24+
25+
"""
26+
if not self.is_leaf:
27+
return
28+
29+
if self.is_parity or self.is_repetition:
30+
return
31+
32+
if self.is_zero:
33+
self._beta = compute_beta_zero_node(self.alpha)
34+
if self.is_one:
35+
self._beta = compute_beta_one_node(self.alpha)
36+
37+
def get_node_type(self):
38+
"""Get the type of Fast SCAN Node.
39+
40+
* Zero node - [0, 0, 0, 0, 0, 0, 0, 0];
41+
* One node - [1, 1, 1, 1, 1, 1, 1, 1];
42+
* Single parity check node - [0, 1, 1, 1, 1, 1, 1, 1];
43+
* Repetition node - [0, 0, 0, 0, 0, 0, 0, 1].
44+
45+
Or other type.
46+
47+
"""
48+
if self._check_is_zero(self._mask):
49+
return self.ZERO_NODE
50+
if self._check_is_one(self._mask):
51+
return self.ONE_NODE
52+
if self._check_is_rep(self._mask):
53+
return self.REPETITION
54+
if self._check_is_spc(self._mask):
55+
return self.SINGLE_PARITY_CHECK
56+
return self.OTHER
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from .codec import RCSCANPolarCodec
22
from .decoder import RCSCANDecoder
33
from .functions import *
4-
from .node import INFINITY, RCSCANNode
4+
from .node import RCSCANNode

python_polar_coding/polar_codes/rc_scan/decoder.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def clean_before_decoding(self):
4848
4949
"""
5050
for node in PreOrderIter(self._decoding_tree):
51-
if not node.is_leaf:
51+
if not (node.is_zero or node.is_one):
5252
node.beta *= 0
5353

5454
def compute_intermediate_alpha(self, leaf):
@@ -81,8 +81,9 @@ def compute_intermediate_beta(self, node):
8181

8282
@property
8383
def result(self):
84-
if self.is_systematic:
85-
return make_hard_decision(self.root.alpha + self._compute_result_beta())
84+
if not self.is_systematic:
85+
raise TypeError('Code must be systematic')
86+
return make_hard_decision(self.root.alpha + self._compute_result_beta())
8687

8788
@staticmethod
8889
def compute_left_alpha(parent_alpha, beta):

python_polar_coding/polar_codes/rc_scan/node.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ def compute_leaf_beta(self):
1414
in leaves.
1515
1616
"""
17-
if self.is_zero or self.is_one:
18-
return
1917

2018
def initialize_leaf_beta(self):
2119
"""Initialize BETA values on tree building.

python_polar_coding/simulation/simulation.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
GeneralizedFastSSCPolarCodec,
1010
RCSCANPolarCodec,
1111
)
12+
from ..polar_codes.fast_scan import FastSCANCodec
1213
from . import functions, http
1314

1415

@@ -17,7 +18,13 @@ class CodeTypes:
1718
FAST_SSC = 'fast-ssc'
1819
RC_SCAN = 'rc_scan'
1920
G_FAST_SSC = 'g-fast-ssc'
20-
ALL = [FAST_SSC, RC_SCAN]
21+
FAST_SCAN = 'fast-scan'
22+
ALL = [
23+
FAST_SSC,
24+
RC_SCAN,
25+
G_FAST_SSC,
26+
FAST_SCAN,
27+
]
2128

2229

2330
class ChannelTypes:
@@ -28,6 +35,7 @@ class ChannelTypes:
2835
CodeTypes.FAST_SSC: FastSSCPolarCodec,
2936
CodeTypes.RC_SCAN: RCSCANPolarCodec,
3037
CodeTypes.G_FAST_SSC: GeneralizedFastSSCPolarCodec,
38+
CodeTypes.FAST_SCAN: FastSCANCodec,
3139
}
3240

3341

0 commit comments

Comments
 (0)