Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
8 views
# # To measure the total XOR row operations needed in forming triangular matrix in Systematic Random Code (SYSRC). # # By Chong Zan Kai [email protected] # Written on 3-Feb-2015. # class Systematic_Random_Code_Matrix_Solver: def __init__(self): self.__total_xor_row_operation = 0 # # Return the total execution of XOR row operations. # def get_total_xor_row_operation(self): return self.__total_xor_row_operation # # Search for a particular row in which its target_col is non-zero. # def search_pivot_row(self, target_col, target_mat): for row in range(target_mat.nrows()): if target_mat[row, target_col] == 1: return row return -1 # # Form triangle matrix utilising the received identity matrix. # def form_triangle_matrix(self, idn_mat, rand_mat): # Result matrix -- zero row. result_mat = matrix(GF(2), 0, idn_mat.ncols()) for pivot_col in range(idn_mat.ncols()): pivot_row = self.search_pivot_row(pivot_col, idn_mat) if pivot_row >=0 : result_mat = result_mat.stack( idn_mat[pivot_row] ) else: pivot_row = self.search_pivot_row(pivot_col, rand_mat) assert (pivot_row >=0 ) # nothing I can do it cannot find any pivot row. result_mat = result_mat.stack( rand_mat[pivot_row] ) rand_mat = rand_mat.delete_rows([pivot_row]) for row in range(rand_mat.nrows()): # Note! I remove the following line such that the solver will XOR every row!!!!!!!!! # if rand_mat[row, pivot_col] == 1: rand_mat[row] += result_mat[-1] # XOR row operation. self.__total_xor_row_operation += 1 # return result_mat # # # # To measure the total XOR row operation in invert the (k+10) x k augmented matrix that # consists of $total_idn_row identity rows. # def calc_xor_row_operation(total_idn_row, k): idn_mat = identity_matrix(GF(2), k) idn_mat = idn_mat[range(total_idn_row), :] total_rand_row = k+10 - idn_mat.nrows() rand_mat = random_matrix(GF(2), total_rand_row, k) # Inverting matrix solver = Systematic_Random_Code_Matrix_Solver() result_mat = solver.form_triangle_matrix(idn_mat,rand_mat) return solver.get_total_xor_row_operation() #----------------------------------------------------------------------- # Test #----------------------------------------------------------------------- import random # set_random_seed(333) k = 40 for i in range(0, 10): result = calc_xor_row_operation(i, k) print 'idn_row = %d, rand_row = %d and XOR row operation = %d' % (i, k+10-i, result)
idn_row = 0, rand_row = 50 and XOR row operation = 1180 idn_row = 1, rand_row = 49 and XOR row operation = 1180 idn_row = 2, rand_row = 48 and XOR row operation = 1179 idn_row = 3, rand_row = 47 and XOR row operation = 1177 idn_row = 4, rand_row = 46 and XOR row operation = 1174 idn_row = 5, rand_row = 45 and XOR row operation = 1170 idn_row = 6, rand_row = 44 and XOR row operation = 1165 idn_row = 7, rand_row = 43 and XOR row operation = 1159 idn_row = 8, rand_row = 42 and XOR row operation = 1152 idn_row = 9, rand_row = 41 and XOR row operation = 1144