def test_code(self): config = yaml.safe_load(open('config-test.yml')) for i in range(2 ** self.k): code, distorted_code, error = encode( coder_file=config['coder-generator-test'], message=i, m_length=self.k, error=74) # 000000000000001001010 assert transpose_matrix( matrix=multiply_matrices( matrix1=read_file_to_list(config['decoder-parity-check-test']), columns_count1=self.n, matrix2=transpose_matrix([code], self.n), columns_count2=1 ), columns_count=1)[0] == 0 for i in range(2 ** self.k): code, distorted_code, error = encode( coder_file=config['coder-generator-test'], message=i, m_length=self.k) if get_hamming_weight(error) <= self.t: assert transpose_matrix( matrix=multiply_matrices( matrix1=read_file_to_list(config['decoder-parity-check-test']), columns_count1=self.n, matrix2=transpose_matrix([code], self.n), columns_count2=1 ), columns_count=1)[0] == 0
def decode(parity_check_file, n, syndrome_file, distorted_code): parity_check_matrix = read_file_to_list(name=parity_check_file) syndrome_decoding_table = read_file_to_dict(name=syndrome_file) syndrome = transpose_matrix(matrix=multiply_matrices( matrix1=parity_check_matrix, columns_count1=n, matrix2=transpose_matrix(matrix=[distorted_code], columns_count=n), columns_count2=1), columns_count=1)[0] return syndrome_decoding_table[0].index( distorted_code ^ syndrome_decoding_table[syndrome][0])
def test_transpose_matrix(self): n = 10 r = 7 d = 1 matrix, a_matrix_transposed = fill_parity_check_matrix_and_a_matrix_transposed( n=n, r=r, d=d) transposed_matrix = transpose_matrix(matrix=matrix, number_of_columns=n) doubly_transposed_matrix = transpose_matrix(matrix=transposed_matrix, number_of_columns=r) for i in range(len(doubly_transposed_matrix)): assert doubly_transposed_matrix[i] == matrix[i]
def test_multiply_matrices(self): parity_check_matrix, a_matrix_transposed = fill_parity_check_matrix_and_a_matrix_transposed( n=self.n, r=self.r, d=self.d) generator_matrix = fill_generator_matrix_from_a_matrix_transposed( a_matrix_transposed=a_matrix_transposed, k=self.k, r=self.r) multiplied_matrix = multiply_matrices(matrix1=parity_check_matrix, num_col_m1=self.n, matrix2=transpose_matrix( generator_matrix, self.n), num_col_m2=self.k) for i in multiplied_matrix: assert i == 0