void MAIAllocator::Finish() { gsl_vector_complex_free(Hchan); gsl_matrix_complex_free(Hmat); gsl_matrix_complex_free(huu); gsl_matrix_uint_free(Hperm); gsl_permutation_free(p); gsl_vector_free(huserabs); gsl_vector_uint_free(nextcarr); gsl_vector_uint_free( usedcarr); gsl_vector_uint_free( errs ); gsl_matrix_free(habs); gsl_matrix_uint_free(signature_frequencies); gsl_matrix_uint_free(signature_frequencies_init); gsl_matrix_free(signature_powers); gsl_rng_free(ran); gsl_matrix_complex_free(transform_mat); switch (Mode()) { case 4: // destroy the Kernel pKernel->Shutdown() ; delete pKernel; break; } }
/** * Destructor for a delayed vector field, desallocating. */ vectorFieldDelay::~vectorFieldDelay() { for (size_t d = 0; d < nDelays; d++) { delete fields->at(d); } delete fields; gsl_vector_uint_free(delays); gsl_vector_free(work); }
void MBlockUser::Finish() { //////// post processing gsl_vector_uint_free(gray_encoding); gsl_matrix_complex_free(coding_mat); gsl_matrix_complex_free(selection_mat); gsl_matrix_complex_free(transform_mat); gsl_matrix_complex_free(outmat); gsl_vector_complex_free(tmp); gsl_vector_complex_free(tmp1); gsl_vector_complex_free(tmp2); }
void ViterbiDecoder::Run() { int DataLength, CodeLength, i, j, index; int *g_encoder; int nn, KK, mm, max_states, code_type, dec_type; double elm; float *input_c_float; int *output_u_int; int *out0, *out1, *state0, *state1; /////////////////////////////////////////////// /////////////////////////////////////////////// /////////////////////////////////////////////// /* first input is the data word */ gsl_vector_class inputobj = vin1.GetDataObj(); CodeLength = inputobj.vec->size; /* number of data bits */ /* convert the input into float */ input_c_float = (float *)calloc( CodeLength, sizeof(float) ); for (i=0;i<CodeLength;i++) input_c_float[i] = gsl_vector_get(inputobj.vec,i); /* default values */ code_type = CType(); nn = gp_mat->size1; KK = gp_mat->size2; mm = KK - 1; max_states = 1 << mm; /* 2^mm */ /* determine the DataLength */ DataLength = (CodeLength/nn)-mm; /* Convert code polynomial to binary */ g_encoder = (int*)calloc(nn, sizeof(int) ); for (i = 0;i<nn;i++) { for (j=0;j<KK;j++) { elm = gsl_matrix_get(gp_mat,i,j); if (elm != 0) { g_encoder[i] = g_encoder[i] + (int) pow(2,(KK-j-1)); } } } /* create appropriate transition matrices */ out0 = (int *)calloc( max_states, sizeof(int) ); out1 = (int *)calloc( max_states, sizeof(int) ); state0 = (int *)calloc( max_states, sizeof(int) ); state1 = (int *)calloc( max_states, sizeof(int) ); if ( code_type ) { nsc_transit( out0, state0, 0, g_encoder, KK, nn ); nsc_transit( out1, state1, 1, g_encoder, KK, nn ); } else { rsc_transit( out0, state0, 0, g_encoder, KK, nn ); rsc_transit( out1, state1, 1, g_encoder, KK, nn ); } gsl_vector_uint *output = gsl_vector_uint_alloc(DataLength); output_u_int = (int *)calloc( DataLength, sizeof(int) ); /* Run the Viterib algorithm */ Viterbi( output_u_int, out0, state0, out1, state1, input_c_float, KK, nn, DataLength ); /* cast to outputs */ for (j=0;j<DataLength;j++) { gsl_vector_uint_set(output,j,output_u_int[j]); } gsl_vector_uint_class outobj(output); // outobj.show(); vout1.DeliverDataObj(outobj); /////////////////////////////////////////////// /////////////////////////////////////////////// /////////////////////////////////////////////// /* Clean up memory */ free( out0 ); free( out1 ); free( state0 ); free( state1 ); free( g_encoder ); free( input_c_float ); free( output_u_int ); gsl_vector_uint_free(output); }
/*! Computes assignment matrix for M. */ int Hungarian(const gsl_matrix * const M, const bool convToMinAsg, gsl_matrix * const Assignment) { int res, z0_r, z0_c; bool done = false; unsigned int next = STEP1; gsl_vector_uint *rowCov, *colCov; gsl_matrix_uint *mask; gsl_matrix_int *path; gsl_matrix *MCopy; MCopy = gsl_matrix_alloc(M->size1, M->size2); gsl_matrix_memcpy(MCopy, M); if(convToMinAsg == true) { res = ConvertToMinAsg(MCopy); if(res != GSL_SUCCESS) return res; } // Allocate memory rowCov = gsl_vector_uint_alloc(M->size1); colCov = gsl_vector_uint_alloc(M->size2); mask = gsl_matrix_uint_alloc(M->size1, M->size2); path = gsl_matrix_int_calloc(ceil(((float)(mask->size1*mask->size2))/2), 2 ); // Initialize gsl_vector_uint_set_all(rowCov, UNCOVERED); gsl_vector_uint_set_all(colCov, UNCOVERED); gsl_matrix_uint_set_all(mask, UNMASKED); while(done == false) { switch(next) { case STEP1: next = Step1(MCopy); #ifdef VERBOSE Matrix_print_with_mask(MCopy, mask, rowCov, colCov, "Post Step 1"); PrintCover( rowCov, colCov, "Post Step 1 Cover"); #endif break; case STEP2: next = Step2(MCopy, mask, rowCov, colCov); #ifdef VERBOSE Matrix_print_with_mask(MCopy, mask, rowCov, colCov, "Post Step 2"); PrintCover( rowCov, colCov, "Post Step 2 Cover"); #endif break; case STEP3: next = Step3(MCopy, mask, colCov); #ifdef VERBOSE Matrix_print_with_mask(MCopy, mask, rowCov, colCov, "Post Step 3"); PrintCover( rowCov, colCov, "Post Step 3 Cover"); #endif break; case STEP4: next = Step4(MCopy, mask, rowCov, colCov, &z0_r, &z0_c); #ifdef VERBOSE Matrix_print_with_mask(MCopy, mask, rowCov, colCov, "Post Step 4"); PrintCover( rowCov, colCov, "Post Step 4 Cover"); #endif break; case STEP5: next = Step5(mask, path, rowCov, colCov, z0_r, z0_c); #ifdef VERBOSE Matrix_print_with_mask(MCopy, mask, rowCov, colCov, "Post Step 5"); PrintCover( rowCov, colCov, "Post Step 5 Cover"); #endif break; case STEP6: next = Step6(MCopy, rowCov, colCov); #ifdef VERBOSE Matrix_print_with_mask(MCopy, mask, rowCov, colCov, "Post Step 6"); PrintCover( rowCov, colCov, "Post Step 6 Cover"); #endif break; case DONE: #ifdef VERBOSE Matrix_print_with_mask(MCopy, mask, rowCov, colCov, "DONE"); #endif UpdateAssignment(mask, Assignment); done = true; break; default: done = true; fprintf(stderr, "Error!\n"); } } // Release memory gsl_matrix_free(MCopy); gsl_vector_uint_free(rowCov); gsl_vector_uint_free(colCov); gsl_matrix_uint_free(mask); gsl_matrix_int_free(path); return GSL_SUCCESS; }
void MBitBer::Finish() { ofstream ofs; string fn( fname() ); if (fn != "cout") ofs.open( fname(),ios::app); if (! ofs ) { cerr << BlockName << ": error opening " << fn << endl; exit(_ERROR_OPEN_FILE_); } unsigned int minimum, maximum, sum; minimum = (unsigned int)GSL_POSINF; maximum = sum = 0; for (int u=0;u<M();u++) { // user loop if (gsl_vector_uint_get(bitcount,u)!=0) { if (fn != "cout") { ofs.width(NUMWIDTH); ofs << u; ofs.width(NUMWIDTH); ofs << value(); ofs.width(NUMWIDTH); ofs << 1.0*gsl_vector_uint_get(errcount,u)/gsl_vector_uint_get(bitcount,u); ofs.width(NUMWIDTH); ofs << gsl_vector_uint_get(bitcount,u); ofs.width(NUMWIDTH); ofs << gsl_vector_uint_get(errcount,u) << endl; } else { cout.width(NUMWIDTH); cout << u; cout.width(NUMWIDTH); cout << value(); cout.width(NUMWIDTH); cout << 1.0*gsl_vector_uint_get(errcount,u)/gsl_vector_uint_get(bitcount,u); cout.width(NUMWIDTH); cout << gsl_vector_uint_get(bitcount,u); cout.width(NUMWIDTH); cout << gsl_vector_uint_get(errcount,u) << endl; } } // find maximum if (gsl_vector_uint_get(errcount,u)>maximum) maximum = gsl_vector_uint_get(errcount,u); // find minimum if (gsl_vector_uint_get(errcount,u)<minimum) minimum = gsl_vector_uint_get(errcount,u); sum += gsl_vector_uint_get(errcount,u); } // user loop // min, max and mean if (gsl_vector_uint_get(bitcount,0)!=0) { if (fn != "cout") { ofs.width(NUMWIDTH); ofs << "min"; ofs.width(NUMWIDTH); ofs << value(); ofs.width(NUMWIDTH); ofs << 1.0*minimum/gsl_vector_uint_get(bitcount,0); ofs.width(NUMWIDTH); ofs << gsl_vector_uint_get(bitcount,0); ofs.width(NUMWIDTH); ofs << minimum << endl; ofs.width(NUMWIDTH); ofs << "max"; ofs.width(NUMWIDTH); ofs << value(); ofs.width(NUMWIDTH); ofs << 1.0*maximum/gsl_vector_uint_get(bitcount,0); ofs.width(NUMWIDTH); ofs << gsl_vector_uint_get(bitcount,0); ofs.width(NUMWIDTH); ofs << maximum << endl; ofs.width(NUMWIDTH); ofs << "mean"; ofs.width(NUMWIDTH); ofs << value(); ofs.width(NUMWIDTH); ofs << 1.0*sum/gsl_vector_uint_get(bitcount,0)/M(); ofs.width(NUMWIDTH); ofs << gsl_vector_uint_get(bitcount,0); ofs.width(NUMWIDTH); ofs << sum/M() << endl; } else { cout.width(NUMWIDTH); cout << "min"; cout.width(NUMWIDTH); cout << value(); cout.width(NUMWIDTH); cout << 1.0*minimum/gsl_vector_uint_get(bitcount,0); cout.width(NUMWIDTH); cout << gsl_vector_uint_get(bitcount,0); cout.width(NUMWIDTH); cout << minimum << endl; cout.width(NUMWIDTH); cout << "max"; cout.width(NUMWIDTH); cout << value(); cout.width(NUMWIDTH); cout << 1.0*maximum/gsl_vector_uint_get(bitcount,0); cout.width(NUMWIDTH); cout << gsl_vector_uint_get(bitcount,0); cout.width(NUMWIDTH); cout << maximum << endl; cout.width(NUMWIDTH); cout << "mean"; cout.width(NUMWIDTH); cout << value(); cout.width(NUMWIDTH); cout << 1.0*sum/gsl_vector_uint_get(bitcount,0)/M(); cout.width(NUMWIDTH); cout << gsl_vector_uint_get(bitcount,0); cout.width(NUMWIDTH); cout << sum/M() << endl; } } ofs.close(); double ebnol=pow(10.0,(value()/10.0)); cout << "\n BPSK reference BER (AWGN) = " << gsl_cdf_ugaussian_Q(sqrt(2*ebnol)) << endl; gsl_vector_uint_free(lasterrs); gsl_vector_uint_free(errcount); gsl_vector_uint_free(bitcount); gsl_vector_uint_free(dumperrs); }
void pvalue(gsl_rng * r, gsl_vector_uint *x, gsl_vector_uint *sums, double *_pvalue, double *_alpha, double *_alpha_score, double *_beta_score, PvalueConfig *config) { fprintf(stderr,"pvalue\n"); assert(x->size == sums->size); size_t i; size_t dim=x->size; unsigned int runs=config->runs; unsigned int N=0; unsigned int NN=0; for(i=0;i<dim;i++) { N+=ELT(x,i); NN+=ELT(sums,i); } printf("N=%i\n",N); double *p=(double*)malloc(sizeof(double)*dim); for(i=0;i<dim;i++) { p[i]=ELT(sums,i)*1.0/NN; } double cutoff = logRV(dim,x,sums,NN); fprintf(stderr,"cutoff = %f\n",cutoff); double rv; unsigned int positives=0; //unsigned int *n=(unsigned int*)malloc(sizeof(unsigned int)*dim); gsl_vector_uint *n=gsl_vector_uint_alloc(dim); for (i = 0; i < runs; i++) { gsl_ran_multinomial (r, dim, N, p, n->data); rv=logRV(dim,n,sums,NN); if (rv <= cutoff) { positives++; /*fprintf(multi,"%i %i %i\t%i\n",n->data[0],n->data[1],n->data[2], n->data[0]+n->data[1]+n->data[2]); */ } } double pvalue=positives*1.0/runs; fprintf(stderr,"%i %i %f",positives,runs,pvalue); *_pvalue=pvalue; pvalue_alpha_beta(N,4,1,_alpha,_beta_score); if (N!=0) { *_alpha=0.07/sqrt(N); } *_alpha_score=1.0-pvalue/(*_alpha); fprintf (stderr,"\n"); free(p); //free(n); gsl_vector_uint_free(n); }
void pvalue_all_3d(gsl_rng * r, gsl_vector_uint *x, gsl_vector_uint *sums) { assert(x->size == sums->size); size_t i,j,k; size_t dim=x->size; unsigned int N=0; unsigned int NN=0; for(i=0;i<dim;i++) { N+=ELT(x,i); NN+=ELT(sums,i); } double *p=(double*)malloc(sizeof(double)*dim); for(i=0;i<dim;i++) { p[i]=((double)ELT(sums,i))/NN; } double cutoff = logRV(dim,x,sums,NN); fprintf(stderr,"cutoff = %f\n",cutoff); double rv; unsigned int positives=0; gsl_vector_uint *n=gsl_vector_uint_alloc(dim); FILE *graph_pos,*graph_neg; char buff[256]; sprintf(buff,"pvalue_graph_pos-%i-%i-%i.dat",x->data[0],x->data[1],x->data[2]); if ( (graph_pos=fopen(buff,"w+"))==NULL) { fprintf(stderr,"ERROR: Can't open pvalue_graph_pos.dat"); exit(-1); } sprintf(buff,"pvalue_graph_neg-%i-%i-%i.dat",x->data[0],x->data[1],x->data[2]); if ( (graph_neg=fopen(buff,"w+"))==NULL) { fprintf(stderr,"ERROR: Can't open pvalue_graph_neg.dat"); exit(-1); } double pr; double pv=0; unsigned int positivos=0; unsigned int total=0; pr=gsl_ran_multinomial_pdf(dim,p,x->data); printf("pr(x) = %f\n",pr); for (i=0; i <= N;i+=1) { SET_ELT(n,0,i); for(j=0; i+j<= N;j+=1) { SET_ELT(n,1,j); SET_ELT(n,2,N-(i+j)); rv=logRV(dim,n,sums,NN); pr=gsl_ran_multinomial_pdf(dim,p,n->data); //printf("%f %f\n",rv,cutoff); if (rv <= cutoff) { pv+=pr; positives++; fprintf(graph_pos,"%u %u %f\n",i,j,pr); } else { fprintf(graph_neg,"%u %u %f\n",i,j,pr); } total++; } } printf("pos = %u total = %u: ratio = %f\n",positives,total,((double)positives)/total); printf("pvalue2 = %f\n",pv); fclose(graph_pos); fclose(graph_neg); /*for (i = 0; i < runs; i++) { gsl_ran_multinomial (r, dim, N, p, n->data); rv=logRV(dim,n,sums,NN); if (rv <= cutoff) positives++; //fprintf(stderr,"%i: %i %i\t%f\t%i\n",i,n[0],n[1],rv,); }*/ free(p); //free(n); gsl_vector_uint_free(n); }