Skip to content

Commit d6b4dcc

Browse files
author
grigory
committed
Merge branch 'feature/fast-scan-decoder'
2 parents b83b700 + 691e93c commit d6b4dcc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1745
-1236
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
.idea
66
.python-version
77
.pytest_cache
8+
apak/*
89
firestore/*credentials*
910
src*
10-
tests/_trial_temp*
11+
tests/_trial_temp*
12+
venv/

.isort.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ line_length=79
33
length_sort_stdlib=1
44
multi_line_output=3
55
include_trailing_comma=True
6+
skip=apak,venv

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/__init__.py

100644100755
File mode changed.

python_polar_coding/polar_codes/__init__.py

100644100755
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +0,0 @@
1-
from .fast_ssc import FastSSCPolarCodec
2-
from .g_fast_ssc import GeneralizedFastSSCPolarCodec
3-
from .rc_scan import RCSCANPolarCodec
4-
from .sc import SCPolarCodec
5-
from .sc_list import SCListPolarCodec

python_polar_coding/polar_codes/base/__init__.py

100644100755
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from .codec import BaseCRCPolarCodec, BasePolarCodec
22
from .constants import *
3-
from .decoder import BaseDecoder
3+
from .decoder import BaseDecoder, BaseTreeDecoder
44
from .decoding_path import DecodingPathMixin
55
from .encoder import *
66
from .functions import *
7+
from .node import *

python_polar_coding/polar_codes/base/decoder.py

Lines changed: 97 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import abc
22

33
import numpy as np
4+
from anytree import PreOrderIter
45

56

67
class BaseDecoder(metaclass=abc.ABCMeta):
@@ -14,13 +15,13 @@ def __init__(self, n, mask: np.array, is_systematic: bool = True):
1415

1516
def decode(self, received_llr: np.array) -> np.array:
1617
decoded = self.decode_internal(received_llr)
17-
return self.get_result(decoded)
18+
return self.extract_result(decoded)
1819

1920
@abc.abstractmethod
2021
def decode_internal(self, received_llr: np.array) -> np.array:
2122
"""Implementation of particular decoding method."""
2223

23-
def get_result(self, decoded: np.array) -> np.array:
24+
def extract_result(self, decoded: np.array) -> np.array:
2425
"""Get decoding result.
2526
2627
Extract info bits from decoded message due to polar code mask.
@@ -32,3 +33,97 @@ def get_result(self, decoded: np.array) -> np.array:
3233
if self.mask[i] == 1:
3334
decoded_info = np.append(decoded_info, decoded[i])
3435
return np.array(decoded_info, dtype=np.int)
36+
37+
38+
class BaseTreeDecoder(metaclass=abc.ABCMeta):
39+
"""Basic class for polar decoder that use tree for decoding."""
40+
41+
node_class: 'BaseDecodingNode'
42+
43+
def __init__(self, n, mask: np.array):
44+
self.N = mask.shape[0]
45+
self.n = n
46+
self.mask = mask
47+
48+
self._decoding_tree = self._setup_decoding_tree()
49+
self._position = 0
50+
51+
def __call__(self, received_llr: np.array) -> np.array:
52+
decoded = self.decode(received_llr)
53+
return self.extract_result(decoded)
54+
55+
@property
56+
def leaves(self):
57+
return self._decoding_tree.leaves
58+
59+
@property
60+
def root(self):
61+
"""Returns root node of decoding tree."""
62+
return self._decoding_tree.root
63+
64+
@property
65+
def result(self):
66+
return self.root.beta
67+
68+
def decode(self, received_llr: np.array) -> np.array:
69+
"""Implementation of decoding using tree."""
70+
self._set_initial_state(received_llr)
71+
self._reset_tree_computed_state()
72+
73+
for leaf in self.leaves:
74+
self._set_decoder_state(self._position)
75+
self._compute_intermediate_alpha(leaf)
76+
leaf()
77+
self._compute_intermediate_beta(leaf)
78+
self._set_next_state(leaf.N)
79+
80+
return self.result
81+
82+
def extract_result(self, decoded: np.array) -> np.array:
83+
"""Get decoding result.
84+
85+
Extract info bits from decoded message due to polar code mask.
86+
87+
"""
88+
decoded_info = list()
89+
90+
for i in range(self.N):
91+
if self.mask[i] == 1:
92+
decoded_info = np.append(decoded_info, decoded[i])
93+
return np.array(decoded_info, dtype=np.int)
94+
95+
def _setup_decoding_tree(self, ):
96+
"""Setup decoding tree."""
97+
return self.node_class(mask=self.mask)
98+
99+
def _set_initial_state(self, received_llr):
100+
"""Initialize decoder with received message."""
101+
self.current_state = np.zeros(self.n, dtype=np.int8)
102+
self.previous_state = np.ones(self.n, dtype=np.int8)
103+
104+
# LLR values at intermediate steps
105+
self._position = 0
106+
self._decoding_tree.root.alpha = received_llr
107+
108+
def _reset_tree_computed_state(self):
109+
"""Reset the state of the tree before decoding"""
110+
for node in PreOrderIter(self._decoding_tree):
111+
node.is_computed = False
112+
113+
def _set_decoder_state(self, position):
114+
"""Set current state of the decoder."""
115+
bits = np.unpackbits(
116+
np.array([position], dtype=np.uint32).byteswap().view(np.uint8)
117+
)
118+
self.current_state = bits[-self.n:]
119+
120+
@abc.abstractmethod
121+
def _compute_intermediate_alpha(self, leaf):
122+
"""Compute intermediate Alpha values (LLR)."""
123+
124+
@abc.abstractmethod
125+
def _compute_intermediate_beta(self, node):
126+
"""Compute intermediate Beta values (Bits or LLR)."""
127+
128+
def _set_next_state(self, leaf_size):
129+
self._position += leaf_size

python_polar_coding/polar_codes/base/functions.py

Lines changed: 0 additions & 52 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from .alpha import (
2+
compute_alpha,
3+
compute_left_alpha,
4+
compute_right_alpha,
5+
function_1,
6+
function_2,
7+
)
8+
from .beta_hard import (
9+
compute_beta_hard,
10+
compute_parent_beta_hard,
11+
make_hard_decision,
12+
)
13+
from .beta_soft import compute_beta_soft
14+
from .encoding import compute_encoding_step
15+
from .node_types import NodeTypes, get_node_type

0 commit comments

Comments
 (0)