15 #include "weilei_lib/my_lib.h"
16 #include <itpp/itbase.h>
46 for (
int i=0;i<L;i++){
64 for (
int i=0;i<L;i++){
87 for (
int i=0;i<L-1;i++){
98 switch(generator_flag){
111 GF2mat Bj=
kron(Aj,gf2dense_eye(P.rows()))
112 .concatenate_horizontal(
kron(gf2dense_eye(Aj.rows()),P))
113 .concatenate_vertical(
114 GF2mat(Ajless.rows()*P.cols(),Aj.cols()*P.rows()).concatenate_horizontal(
115 kron(Ajless,gf2dense_eye(P.cols()))
123 for (
int i=0;i<m-1;i++){
129 static GF2mat B[MAX_m];
131 B1=
kron(A1,gf2dense_eye(P.rows()))
132 .concatenate_horizontal(
kron(gf2dense_eye(A1.rows()),P));
135 GF2mat B2=
kron(gf2dense_eye( A1.cols() ),P)
136 .concatenate_vertical(
kron(A1,gf2dense_eye(P.cols())));
141 for (
int j=2;j<m;j++){
145 GF2mat Amless = A[m-2];
146 GF2mat Bm=
kron(gf2dense_eye( Amless.cols() ),P)
147 .concatenate_vertical(
kron(Amless,gf2dense_eye(P.cols())));
154 for (
int i=1;i<m+1;i++){
155 for (
int j=0;j<i+1;j++){
156 cout<<nkd[i][j]<<
"\t";
165 cout<<
"#Expected value calculated from Table 1:"<<endl;
169 for (
int i=2;i<m+1;i++){
170 n[i][0]=n[i-1][0]*P[i-1].rows();
171 n[i][i]=n[i-1][i-1]*P[i-1].cols();
172 for (
int j=1;j<i;j++){
173 n[i][j]=n[i-1][j]*P[i-1].rows()+n[i-1][j-1]*P[i-1].cols();
176 cout<<
"n0\tn1\tn2\tn3\tn4"<<endl;
180 cout<<
"-----------------------------------"<<endl;
181 for (
int i=0;i<m;i++){
190 for (
int i=2;i<m+1;i++){
191 kC[i][0]=kC[i-1][0]*kt[i-1];
192 kC[i][i]=kC[i-1][i-1]*k[i-1];
193 for (
int j=1;j<i;j++){
194 kC[i][j] = kC[i-1][j-1]*k[i-1]+kC[i-1][j]*kt[i-1];
197 cout<<
"k0\tk1\tk2\tk3\tk4"<<endl;
200 int delta[m],delta_tilde[m];
203 cout<<
"-----------------------------------parameters of P:"<<endl;
204 cout<<
"row\tcol\trank\tkappa,delta,kappa_tilde,delta_tilde"<<endl;
205 for (
int i=0;i<m;i++){
209 cout<<P[i].rows()<<
"\t"<<P[i].cols()<<
"\t"<<P[i].row_rank()<<
"\t";
210 cout<<k[i]<<
"\t"<<dl1<<
"\t"<<kt[i]<<
"\t"<<dl2<<
"\t"<<endl;
214 cout<<
"-----------------------------------"<<endl;
218 dl[1][0]= (kt[0]>0)? 1:
INF;
219 for (
int i=2;i<m+1;i++){
220 dl[i][i]=dl[i-1][i-1]*delta[i-1];
221 dl[i][0]=(kt[i-1]>0)? dl[i-1][0]:
INF;
222 for (
int j=1;j<i;j++){
223 dl[i][j]= (kt[i-1]>0)? min(dl[i-1][j-1]*delta[i-1],dl[i-1][j]) : dl[i-1][j-1]*delta[i-1];
228 for (
int i=1;i<m+1;i++){
229 for (
int j=0;j<i+1;j++){
236 vector<int> dist(m*(m+1)*2);
238 for (
int i=1;i<m+1;i++){
239 for (
int j=0;j<i+1;j++){
240 dist[index]=dl[i][j];
247 dr[1][0]=delta_tilde[0];
248 dr[1][1]= (k[0]>0)? 1:
INF;
249 for (
int i=2;i<m+1;i++){
250 dr[i][0]=dr[i-1][0]*delta_tilde[i-1];
251 dr[i][i]=(k[i-1]>0)? dr[i-1][i-1]:
INF;
252 for (
int j=1;j<i;j++){
253 dr[i][j]= (k[i-1]>0)? min(dr[i-1][j]*delta_tilde[i-1],dr[i-1][j-1]) : dr[i-1][j]*delta_tilde[i-1];
257 for (
int i=1;i<m+1;i++){
258 for (
int j=0;j<i+1;j++){
268 for (
int i=1;i<m+1;i++){
269 for (
int j=0;j<i+1;j++){
270 dist[index]=dr[i][j];
277 int d_min[m+1][
MAX_M];
278 for (
int i=1;i<m+1;i++){
279 for (
int j=0;j<i+1;j++){
280 d_min[i][j]=min(dl[i][j],dr[i][j]);
283 cout<<
"d0\td1\td2\td3\td4\td_min=min(d_left,d_right)"<<endl;
285 cout<<
"d0\td1\td2\td3\td4\td_left"<<endl;
287 cout<<
"d0\td1\td2\td3\td4\td_right"<<endl;
295 int parameterC(GF2mat *B1,
int m,
int m_max, vector<int> dist){
301 for (
int i=0;i<m;i++){
302 r[i]=(B1+i)->row_rank();
303 cout<<(B1+i)->rows()<<
"\t";
306 cout<<(B1+m-1)->cols()<<endl;
308 for (
int i=0;i<m-1;i++){
309 int k = (B1+i)->cols() - r[i] -r[i+1];
321 for (
int i=0;i<m-1;i++){
322 int index = m*(m+1)/2+i;
330 for (
int i=0;i<m-1;i++){
331 int index = m_max*(m_max+1)+m*(m+1)/2+i;
339 int saveC(GF2mat *B1,
int m,
char * folder_Cm){
341 for (
int i=0;i<m;i++){
344 sprintf(filename,
"%s/C%d_%d.mm",folder_Cm,m,i);
358 for (
int i=0;i<x;i++){
359 for (
int j=0;j<y;j++){
360 if (randu()<p) P.set(i,j,1);
375 cout<<Aj.rows()<<
"x"<<Aj.cols()<<endl;
376 cout<<Ajplus.rows()<<
"x"<<Ajplus.cols()<<endl;
377 cout<<Bj.rows()<<
"x"<<Bj.cols()<<endl;
378 cout<<Bjplus.rows()<<
"x"<<Bjplus.cols()<<endl;
383 int rank_of_Aj =Aj.transpose().T_fact(T,U,P);
384 GF2mat C = T.get_submatrix(rank_of_Aj,0,Aj.cols()-1,Aj.cols()-1);
386 bvec codeword=zeros_b(Aj.cols());
387 bvec zero=zeros_b(Aj.cols());
388 for (
int i=0;i<C.rows();i++){
389 codeword = C.get_row(i);
390 int wt = BERC::count_errors(zero,codeword);
392 cout<<
"codeword : "<<codeword<<endl;
396 cout<<Aj*codeword<<endl;
400 GF2mat x(1,Aj.cols());
401 x.set_row(0,codeword);
404 z.set_size(1,Bj.cols(),
true);
406 if ( (Bj*z.transpose()).is_zero() ){
407 cout<<
"Bj*z=0"<<endl;
409 GF2mat BjplusT=Bjplus.transpose();
410 GF2mat Bz=BjplusT.concatenate_vertical(z);
411 cout<<Bjplus.row_rank()<<
"<>"<<Bz.rows()<<
"<>"<<Bz.row_rank()<<endl;
421 cout<<Aj.rows()<<
"x"<<Aj.cols()<<endl;
422 cout<<Ajplus.rows()<<
"x"<<Ajplus.cols()<<endl;
423 cout<<Bj.rows()<<
"x"<<Bj.cols()<<endl;
424 cout<<Bjplus.rows()<<
"x"<<Bjplus.cols()<<endl;
425 cout<<
"check2"<<endl;
429 int rank_of_Aj =Aj.transpose().T_fact(T,U,P);
430 GF2mat C = T.get_submatrix(rank_of_Aj,0,Aj.cols()-1,Aj.cols()-1);
432 bvec codeword=zeros_b(Aj.cols());
433 bvec zero=zeros_b(Aj.cols());
434 for (
int i=0;i<C.rows();i++){
435 codeword = C.get_row(i);
436 int wt = BERC::count_errors(zero,codeword);
438 cout<<
"codeword : "<<codeword<<endl;
442 cout<<Aj*codeword<<endl;
444 GF2mat AjplusT=Ajplus.transpose();
445 GF2mat z(1,AjplusT.cols());
446 z.set_row(0,codeword);
447 GF2mat Az=AjplusT.concatenate_vertical(z);
448 cout<<Ajplus.row_rank()<<
"<>"<<Az.rows()<<
"<>"<<Az.row_rank()<<endl;
449 if ( (Aj*Az.transpose()).is_zero() ){
450 cout<<
"Aj*AzT=0"<<endl;
464 GF2mat Gax=*Cm1,Gaz=*(Cm1+1);
466 GF2mat Gbx=*Cm2,Gbz=*(Cm2+1);
467 Gaz=Gaz.transpose(); Gbz=Gbz.transpose();
475 reduce(Gax,Gaz,Gbx,Gbz,dax,daz,dbx,dbz);
476 cout<<
"finish generate_concatenation"<<endl;
480 int generate(GF2mat P[],
int max_m,vector<int> dist,
char * folder_Cm){
491 GF2mat Cms[max_m*(max_m)];
493 for (
int i=2;i<max_m+1;i++){
496 for (
int j=0;j<i;j++){
497 Cms[(i-1)*max_m+j] = *(Cm1+j);
506 int main(
int args,
char ** argv){
514 char * folder_Cm =
"null";
517 char * title = argv[1];
519 double density = 0.5;
520 for (
int i =0;i<max_m;i++){
523 sprintf(pname,
"%s-P%d.mm",title,i+1);
524 px=randi(4,7); py=randi(4,7);
529 int condition_trials=500;
530 for (
int j=0;j<condition_trials;j++){
533 if ( P[i].row_rank() == min(P[i].rows(),P[i].cols()) ){
558 cout<<
"Check result for given P. "<<argv[1]<<endl;
559 for (
int i =0;i<max_m;i++){
560 char * filename_Pi = argv[i+1];
562 cout<<
"P["<<i+1<<
"] "<<P[i]<<endl;
576 cout<<
"Finish "<<argv[1]<<
". Time needed is ";