Skip to content

Commit 7816c53

Browse files
committed
Refactor FEC encoder and decoder modules for improved structure and documentation
- Updated the SyndromeLookupDecoder to inherit from BaseBlockDecoder and enhanced its documentation with detailed explanations and examples. - Refined the WagnerSoftDecisionDecoder to inherit from BaseBlockDecoder, ensuring it adheres to a consistent interface and improved its documentation. - Introduced a new BaseBlockCodeEncoder class to serve as a foundation for various block code encoders, promoting code reuse and clarity. - Enhanced the BCHCodeEncoder, CyclicCodeEncoder, GolayCodeEncoder, HammingCodeEncoder, LinearBlockCodeEncoder, and SystematicLinearBlockCodeEncoder with clearer documentation and removed redundant attributes. - Improved utility functions in the utils module for better clarity and added examples for better usability. - Updated the __init__.py file to reflect the new structure and imports.
1 parent 2f55f44 commit 7816c53

20 files changed

+923
-340
lines changed

docs/api_reference.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@ Forward Error Correction (FEC) decoders for Kaira.
281281
:template: class.rst
282282
:nosignatures:
283283

284+
BaseBlockDecoder
284285
BerlekampMasseyDecoder
285-
BlockDecoder
286286
BruteForceMLDecoder
287287
ReedMullerDecoder
288288
SyndromeLookupDecoder
@@ -302,7 +302,7 @@ Forward Error Correction encoders for Kaira.
302302
:nosignatures:
303303

304304
BCHCodeEncoder
305-
BlockCodeEncoder
305+
BaseBlockCodeEncoder
306306
CyclicCodeEncoder
307307
GolayCodeEncoder
308308
HammingCodeEncoder
@@ -472,6 +472,7 @@ Data utilities for Kaira, including data generation and correlation models.
472472

473473
BinaryTensorDataset
474474
UniformTensorDataset
475+
WynerZivCorrelationDataset
475476

476477

477478
.. currentmodule:: kaira.data

docs/references.bib

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,3 +729,88 @@ @article{golay1949notes
729729
publisher={IEEE},
730730
doi={10.1109/JRPROC.1949.233620}
731731
}
732+
733+
@book{macwilliams1977theory,
734+
title={The Theory of Error-Correcting Codes},
735+
author={MacWilliams, F. Jessie and Sloane, Neil J. A.},
736+
year={1977},
737+
publisher={North-Holland Publishing Company},
738+
isbn={978-0-444-85193-2}
739+
}
740+
741+
@article{reed1954class,
742+
title={A class of multiple-error-correcting codes and the decoding scheme},
743+
author={Reed, Irving S.},
744+
journal={Transactions of the IRE Professional Group on Information Theory},
745+
volume={4},
746+
number={4},
747+
pages={38--49},
748+
year={1954},
749+
publisher={IEEE},
750+
doi={10.1109/TIT.1954.1057465}
751+
}
752+
753+
@article{muller1954application,
754+
title={Application of Boolean algebra to switching circuit design and to error detection},
755+
author={Muller, David E.},
756+
journal={Transactions of the IRE Professional Group on Electronic Computers},
757+
volume={EC-3},
758+
number={3},
759+
pages={6--12},
760+
year={1954},
761+
publisher={IEEE},
762+
doi={10.1109/IREPGELC.1954.6499441}
763+
}
764+
765+
@book{berlekamp1968algebraic,
766+
title={Algebraic Coding Theory},
767+
author={Berlekamp, Elwyn R.},
768+
year={1968},
769+
publisher={McGraw-Hill},
770+
address={New York}
771+
}
772+
773+
@article{massey1969shift,
774+
title={Shift-register synthesis and BCH decoding},
775+
author={Massey, James L.},
776+
journal={IEEE Transactions on Information Theory},
777+
volume={15},
778+
number={1},
779+
pages={122--127},
780+
year={1969},
781+
publisher={IEEE},
782+
doi={10.1109/TIT.1969.1054260}
783+
}
784+
785+
@article{wagner1986simple,
786+
title={A simple algorithm for the exact decoding of the single-parity-check code},
787+
author={Wagner, B. J.},
788+
journal={IEEE Transactions on Information Theory},
789+
volume={32},
790+
number={3},
791+
pages={430--433},
792+
year={1986},
793+
publisher={IEEE},
794+
doi={10.1109/TIT.1986.1057195}
795+
}
796+
797+
@article{hagenauer1989iterative,
798+
title={Iterative decoding of binary block and convolutional codes},
799+
author={Hagenauer, Joachim and Hoeher, Peter},
800+
journal={IEEE Transactions on Information Theory},
801+
volume={42},
802+
number={2},
803+
pages={429--445},
804+
year={1996},
805+
publisher={IEEE},
806+
doi={10.1109/18.485714}
807+
}
808+
809+
@book{proakis2008digital,
810+
title={Digital Communications},
811+
author={Proakis, John G. and Salehi, Masoud},
812+
year={2008},
813+
edition={5th},
814+
publisher={McGraw-Hill Higher Education},
815+
isbn={978-0-07-295716-7}
816+
}

kaira/models/fec/__init__.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
"""Forward Error Correction (FEC) package for Kaira.
22
3-
This package provides implementations of various forward error correction techniques, particularly
4-
focusing on binary error correction codes like block codes, cyclic codes, and more advanced
5-
algebraic codes like BCH codes.
3+
This package provides implementations of various forward error correction techniques, enabling
4+
robust data transmission over noisy channels. FEC codes add redundant information to transmitted
5+
data, allowing receivers to detect and correct errors without retransmission.
6+
7+
Key components:
8+
- algebra: Mathematical foundations for finite fields and binary polynomials
9+
- encoders: Various channel encoding schemes (block codes, algebraic codes, etc.)
10+
- decoders: Implementations of corresponding decoding algorithms
11+
- utils: Utility functions for binary operations and code manipulation
12+
13+
Common FEC codes implemented:
14+
- Block codes: Linear block codes, systematic codes, single parity check
15+
- Cyclic codes: BCH, Reed-Solomon, Golay codes
16+
- Other codes: Hamming, repetition codes, Reed-Muller
17+
18+
These implementations can be used in communication system simulations, coded modulation
19+
schemes, and for educational purposes in information theory and coding :cite:`lin2004error,moon2005error`.
620
"""
721

822
from . import algebra, decoders, encoders, utils

kaira/models/fec/algebra.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
"""Finite field algebra utilities for forward error correction.
22
33
This module provides mathematical utilities for working with binary polynomials and finite fields,
4-
which are essential for many error correction codes such as BCH codes, Reed-Solomon codes, and
5-
other algebraic codes.
4+
which are essential for algebraic error correction codes such as BCH, Reed-Solomon, and others.
5+
6+
The module implements:
7+
- Binary polynomials over GF(2) with efficient arithmetic operations
8+
- Finite fields GF(2^m) with complete field arithmetic
9+
- Field element operations including inverses, minimal polynomials, and traces
10+
11+
These implementations form the mathematical foundation for more complex error correction codes
12+
and are optimized for both correctness and computational efficiency. The module supports both
13+
symbolic manipulations and numeric computations compatible with PyTorch tensors.
14+
15+
:cite:`lin2004error`
16+
:cite:`blahut2003algebraic`
617
"""
718

819
from typing import Any, Dict, List

kaira/models/fec/decoders/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@
2828
>>> decoded = decoder(received)
2929
"""
3030

31-
from .base import BlockDecoder
31+
from .base import BaseBlockDecoder
3232
from .berlekamp_massey import BerlekampMasseyDecoder
3333
from .brute_force_ml import BruteForceMLDecoder
3434
from .reed_muller_decoder import ReedMullerDecoder
3535
from .syndrome_lookup import SyndromeLookupDecoder
3636
from .wagner_soft_decision_decoder import WagnerSoftDecisionDecoder
3737

3838
__all__ = [
39-
"BlockDecoder",
39+
"BaseBlockDecoder",
4040
"SyndromeLookupDecoder",
4141
"BerlekampMasseyDecoder",
4242
"ReedMullerDecoder",

kaira/models/fec/decoders/base.py

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44
Decoders are responsible for recovering the original message from received codewords that
55
may contain errors introduced during transmission over noisy channels.
66
7-
The implementation provides base classes for various types of decoders, following
8-
standard conventions in coding theory :cite:`lin2004error,moon2005error,richardson2008modern`.
7+
The module provides a type-generic architecture that ensures correct pairing between encoders
8+
and their corresponding decoders, while maintaining flexibility for different decoding
9+
algorithms and implementation strategies.
10+
11+
:cite:`lin2004error`
12+
:cite:`moon2005error`
13+
:cite:`richardson2008modern`
914
"""
1015

1116
from abc import ABC, abstractmethod
@@ -15,36 +20,56 @@
1520

1621
from kaira.models.base import BaseModel
1722

18-
from ..encoders.block_code import BlockCodeEncoder
23+
from ..encoders.base import BaseBlockCodeEncoder
1924

20-
T = TypeVar("T", bound=BlockCodeEncoder)
25+
T = TypeVar("T", bound=BaseBlockCodeEncoder)
2126

2227

23-
class BlockDecoder(BaseModel, Generic[T], ABC):
28+
class BaseBlockDecoder(BaseModel, Generic[T], ABC):
2429
"""Base class for block code decoders.
2530
2631
This abstract class provides a common interface and functionality for all types of
2732
block code decoders. It serves as a foundation for specific implementations like
28-
syndrome decoders, Viterbi decoders, BCJR decoders, etc.
33+
syndrome decoders, maximum likelihood decoders, algebraic decoders, and soft-decision
34+
decoders.
35+
36+
The class uses a generic type parameter T to ensure type safety when pairing
37+
encoders with their corresponding decoders. This allows the compiler to catch
38+
type mismatches at development time rather than during runtime.
2939
3040
Attributes:
31-
encoder (T): The encoder instance associated with this decoder
41+
encoder (T): The encoder instance associated with this decoder, providing
42+
access to code parameters and encoding/syndrome calculation methods
3243
3344
Args:
3445
encoder (T): The encoder instance for the code being decoded
3546
*args: Variable positional arguments passed to the base class
3647
**kwargs: Variable keyword arguments passed to the base class
48+
49+
Note:
50+
All concrete implementations must override the forward method to implement
51+
specific decoding algorithms. Decoders may operate on hard-decision (binary)
52+
or soft-decision (real-valued reliability information) inputs depending on
53+
their implementation.
3754
"""
3855

3956
def __init__(self, encoder: T, *args: Any, **kwargs: Any):
40-
"""Initialize the block code decoder."""
57+
"""Initialize the block code decoder with an encoder instance.
58+
59+
The encoder provides essential information about the code parameters and may be used by the
60+
decoder to perform syndrome calculations or other encoding-related operations during the
61+
decoding process.
62+
"""
4163
super().__init__(*args, **kwargs)
4264
self.encoder = encoder
4365

4466
@property
4567
def code_length(self) -> int:
4668
"""Get the code length (n).
4769
70+
The code length is the total number of bits in each codeword,
71+
including both information bits and redundancy bits.
72+
4873
Returns:
4974
The length of the code (number of bits in a codeword)
5075
"""
@@ -54,6 +79,9 @@ def code_length(self) -> int:
5479
def code_dimension(self) -> int:
5580
"""Get the code dimension (k).
5681
82+
The code dimension is the number of information bits in each codeword,
83+
representing the actual data being transmitted.
84+
5785
Returns:
5886
The dimension of the code (number of information bits)
5987
"""
@@ -63,6 +91,9 @@ def code_dimension(self) -> int:
6391
def redundancy(self) -> int:
6492
"""Get the code redundancy (r = n - k).
6593
94+
The redundancy represents the number of parity or check bits added
95+
to the information bits to enable error detection and correction.
96+
6697
Returns:
6798
The redundancy of the code (number of parity bits)
6899
"""
@@ -72,6 +103,10 @@ def redundancy(self) -> int:
72103
def code_rate(self) -> float:
73104
"""Get the code rate (k/n).
74105
106+
The code rate is the ratio of information bits to the total bits,
107+
indicating the coding efficiency. Higher rates mean more efficient
108+
use of the channel but typically lower error correction capability.
109+
75110
Returns:
76111
The rate of the code (ratio of information bits to total bits)
77112
"""
@@ -81,18 +116,28 @@ def code_rate(self) -> float:
81116
def forward(self, received: torch.Tensor, *args: Any, **kwargs: Any) -> Union[torch.Tensor, Tuple[torch.Tensor, torch.Tensor]]:
82117
"""Decode received codewords to recover the original messages.
83118
119+
This method implements the decoding algorithm to estimate the original
120+
message from a potentially corrupted received codeword. Different decoder
121+
implementations will use different algorithms based on the code structure
122+
and desired performance characteristics.
123+
84124
Args:
85-
received: Received codeword tensor. The last dimension should be
86-
a multiple of the code length (n).
87-
*args: Additional positional arguments.
88-
**kwargs: Additional keyword arguments.
125+
received: Received codeword tensor with shape (..., n) or (..., m*n)
126+
where n is the code length and m is some multiple.
127+
*args: Additional positional arguments for specific decoder implementations.
128+
**kwargs: Additional keyword arguments for specific decoder implementations.
89129
90130
Returns:
91131
Either:
92-
- Decoded tensor containing estimated messages
93-
- A tuple of (decoded tensor, additional decoding information)
132+
- Decoded tensor containing estimated messages with shape (..., k) or (..., m*k)
133+
- A tuple of (decoded tensor, additional decoding information such as syndromes,
134+
reliability metrics, or error patterns)
94135
95136
Raises:
96137
ValueError: If the last dimension of received is not a multiple of n.
138+
139+
Note:
140+
The decoding may not perfectly recover the original message if the number
141+
of errors exceeds the error-correcting capability of the code.
97142
"""
98143
raise NotImplementedError("Subclasses must implement forward method")

0 commit comments

Comments
 (0)