Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Began work on hamming codes - Implemented rudimentary version in GF(2) #490

Draft
wants to merge 6 commits into
base: release/0.3.x
Choose a base branch
from

Conversation

abhishekmittal15
Copy link

Hi, I have written a working version of hamming codes in GF(2).
I will soon clean up the functions a little more and add docstrings.

Then we can discuss on implementing extended Hamming codes.

Please let me know, if you have any feedback

Thanks!!

@codecov
Copy link

codecov bot commented Jun 26, 2023

Codecov Report

Patch coverage: 22.41% and project coverage change: -1.44% ⚠️

Comparison is base (a3c2ce2) 96.33% compared to head (34914af) 94.89%.
Report is 9 commits behind head on release/0.3.x.

Additional details and impacted files
@@                Coverage Diff                @@
##           release/0.3.x     #490      +/-   ##
=================================================
- Coverage          96.33%   94.89%   -1.44%     
=================================================
  Files                 46       47       +1     
  Lines               5842     5958     +116     
=================================================
+ Hits                5628     5654      +26     
- Misses               214      304      +90     
Files Changed Coverage Δ
src/galois/_codes/_hamming.py 21.73% <21.73%> (ø)
src/galois/_codes/__init__.py 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@abhishekmittal15
Copy link
Author

abhishekmittal15 commented Jul 14, 2023

Hi @mhostetter , I wanted to share my current thoughts on implementing it for prime fields GF(q) and get your feedback

Parity check matrix generation

Loop over numbers from $1$ to $q^r - 1$

  1. Get the number representation in this field $q$
  2. Then divide this by a( $1 \le a \le q-1$) and then get its integer representation
  3. Check if the number is lesser than the current number or not.
    If for any a from $1$ to $q-1$, after dividing it by a, the integer representation is not lesser than the current number, then it is fine to add the number representation(in vector form) to the parity check matrix, else it is not, as this is just a scaled representation of a column already added earlier.

To get the number representation I am thinking of using the integer_to_poly method in galois\_polys\_conversions.py to get the number representation in the field GF(q) and also use the poly_to_integer to get the base10 number. I think this
approach should work, but my concern is that it will look absurd to be calling a polynomial related function in the hamming class. How do you suggest I go about this?

Error Detection
Detection is the same in any number of errors ⇒ return 1 if syndrome is non zero.

Error Correction
If $c = v+e$ is our corrupted codeword where $v$ is an arbitrary codeword and $e$ is a weight $1$ vector.
This is a single error, and after multiplying to parity check we get $He$. Due to $e$ being a weight $1$ vector, the syndrome is just one of the scaled column of the parity check matrix.
So for this I am thinking of just looping over all the parity columns and then checking if its a scaled vector of the syndrome or not.
This remains the same irrespective of the number of errors since we only attempt to correct $1$ error.

Extended Hamming Code

Parity Check Matrix Generation
Will do the same as above, but now just add $0's$ column and a $1's$ row.

Error Detection
Since I can detect $0, 1, 2$ errors now. To check if there is only $1$ error, I would have to go through all the parity columns and check if the syndrome is a scaled parity column or not. If it is, then I know its 1, else I just return 2.

Error Correction
We now first detect the number of errors, and only try to correct it if the number of errors is 1(if its 2 just ignore it, as it cant be corrected).

Let me know your suggestions.

@mhostetter
Copy link
Owner

To get the number representation I am thinking of using the integer_to_poly method in galois_polys_conversions.py to get the number representation in the field GF(q) and also use the poly_to_integer to get the base10 number. I think this
approach should work, but my concern is that it will look absurd to be calling a polynomial related function in the hamming class. How do you suggest I go about this?

I can't vouch for the algorithm. But here's some thoughts on doing what you describe.

In [1]: import numpy as np

In [2]: import galois

In [3]: q, r = 5, 3

In [4]: GF = galois.GF(q**r)

# Lists all numbers 0 to q^r - 1. You can loop through this array if you'd like
In [5]: GF.elements
Out[5]: 
GF([  0,   1,   2,   3,   4,   5,   6,   7,   8,   9,  10,  11,  12,  13,
     14,  15,  16,  17,  18,  19,  20,  21,  22,  23,  24,  25,  26,  27,
     28,  29,  30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,
     42,  43,  44,  45,  46,  47,  48,  49,  50,  51,  52,  53,  54,  55,
     56,  57,  58,  59,  60,  61,  62,  63,  64,  65,  66,  67,  68,  69,
     70,  71,  72,  73,  74,  75,  76,  77,  78,  79,  80,  81,  82,  83,
     84,  85,  86,  87,  88,  89,  90,  91,  92,  93,  94,  95,  96,  97,
     98,  99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
    112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124],
   order=5^3)

# You can take an integer representation of a field element in GF(q^r) and represent it as a r length vector over GF(q)
# This is equivalent to integer_to_poly()
In [6]: GF(85).vector()
Out[6]: GF([3, 2, 0], order=5)

# Or you can go the other way
# This is equivalent to poly_to_integer()
In [7]: GF.Vector([3, 2, 0])
Out[7]: GF(85, order=5^3)

@abhishekmittal15
Copy link
Author

Hi, yea thats perfect for what I require.

Thanks

@abhishekmittal15
Copy link
Author

abhishekmittal15 commented Jul 15, 2023

Hi @mhostetter , I have extended the Hamming class to support prime fields now.

I have made a demo of its working here

One catch is that the generator matrix is always systematic, not sure if somebody would want it to be non systematic...
Also I was wondering if the detect function could return the actual number of errors, rather than just a boolean value. Or maybe we could create another function that does this?

Let me know what you think about it

@abhishekmittal15
Copy link
Author

Hi @mhostetter,

Wanted to know if you got a chance to look at the current working demo linked in the previous comment?

@mhostetter
Copy link
Owner

@abhishekmittal15 sorry for the delayed response. I did just look at your example notebook. It looks good to me. The API seems consistent with the APIs for the other FEC codes.

@abhishekmittal15
Copy link
Author

Glad to hear that @mhostetter . I have been thinking of supporting haaming codes for extension fields too, but since I am a bit rusty in remembering its theory, I have been giving it a read from my notes and the galois docs. Meanwhile i think i will add the necessary docstrings to the functions, to update the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants