void test_sequence_collection()
{
    ds2i::global_parameters params;
    uint64_t universe = 10000;
    typedef ds2i::sequence_collection<BaseSequence>
        collection_type;
    typename collection_type::builder b(params);

    std::vector<std::vector<uint64_t>> sequences(30);
    for (auto& seq: sequences) {
        double avg_gap = 1.1 + double(rand()) / RAND_MAX * 10;
        uint64_t n = uint64_t(universe / avg_gap);
        seq = random_sequence(universe, n, true);
        b.add_sequence(seq.begin(), seq.back() + 1, n);
    }

    {
        collection_type coll;
        b.build(coll);
        succinct::mapper::freeze(coll, "temp.bin");
    }

    {
        collection_type coll;
        boost::iostreams::mapped_file_source m("temp.bin");
        succinct::mapper::map(coll, m);

        for (size_t i = 0; i < sequences.size(); ++i) {
            test_sequence(coll[i], sequences[i]);
        }
    }
}
void random_posting_data(uint64_t n, uint64_t universe,
                         std::vector<uint64_t>& docs,
                         std::vector<uint64_t>& freqs)
{
    docs = random_sequence(universe, n, true);
    freqs.resize(n);
    std::generate(freqs.begin(), freqs.end(),
                  []() { return (rand() % 256) + 1; });
}
Exemple #3
0
// OK
void test_random_shuffle(){
    int l = 0, h = 9 , len = h-l+1;
    int * order = (int*) malloc(sizeof(int)*len);
    for(int i = 0 ; i < 10 ; ++i){
        random_sequence(l,h,order);
        for(int j = 0 ; j < len ; ++j)
            printf("%d ",order[j]);
        printf("\n");
    }
}
Exemple #4
0
det::num_generator::random_sequence det::num_generator::generate() noexcept {
	size_t* sp = nullptr;
	if (cursor_ + count_ > data_.size()) {
		shuffle();
		sp = data_.data();
		cursor_ = 0;
	} else {
		sp = data_.data() + cursor_;
	}
	cursor_ += count_;
	return random_sequence(sp, count_);

}
    sequence_initialization()
    {
        n = 100000;
        universe = n * 1024;
        seq = random_sequence(universe, n);

        // high granularity to test more corner cases
        params.ef_log_sampling0 = 4;
        params.ef_log_sampling1 = 5;
        succinct::bit_vector_builder bvb;
        ds2i::compact_elias_fano::write(bvb,
                                                  seq.begin(),
                                                  universe, seq.size(),
                                                  params);
        succinct::bit_vector(&bvb).swap(bv);
    }
    sequence_initialization()
    {
        n = 100000;
        universe = n * 3;
        seq = random_sequence(universe, n, true);

        // high granularity to test more corner cases
        params.rb_log_rank1_sampling = 6;
        params.rb_log_sampling1 = 5;
        succinct::bit_vector_builder bvb;
        ds2i::compact_ranked_bitvector::write(bvb,
                                                        seq.begin(),
                                                        universe, seq.size(),
                                                        params);
        succinct::bit_vector(&bvb).swap(bv);
    }
Exemple #7
0
// OK
void test_interleave(){

    int h = 5;
    int w = 8;
    int lm = h*w;
    int* map_out = (int*) malloc(sizeof(int)*lm);
    int** arr = new2d<int>(h,w);
    int* tmp = (int*) malloc(sizeof(int)*lm);

    for(int idx = 0 ; idx < 5 ; ++idx){
        printf("original matrix:\n");
        for(int i = 0 ; i < h ; ++i){
            for(int j = 0 ; j < w ; ++j){
                arr[i][j] = rand()%lm;
                printf("%d\t",arr[i][j]);
            }
            printf("\n");
        }

        printf("\n\nrandom map:\n");
        random_sequence(0,lm-1,map_out);

        for(int i = 0 ; i < lm ; ++i){
            printf("%d ",map_out[i]);
            tmp[i] = arr[map_out[i]/w][map_out[i]%w];
        }

        printf("\n\nmatrix after deinterleave:\n");

        deinterleave(tmp,map_out,lm);

        for(int i = 0 ; i < h ; ++i){
            for(int j = 0 ; j < w ; ++j){
                printf("%d\t",tmp[i*w+j]);
            }
            printf("\n");
        }
        printf("\n\n");

    }

    free(map_out);
    delete2d<int>(arr);
    free(tmp);

}
Exemple #8
0
void random_bits(char *output, int len) {
	int j,b,k,tmp;
	int *ptr;
	ptr = random_sequence(DIV(len,sizeof(int)*8));
	b=k=0;
	for (j=0;j<len;j++) {
		if (!b) {
			tmp = ptr[k];
			b = sizeof(int)*8;
			k++;
		}
		if (tmp & 0x1) {
			output[j] = 1;
		} else {
			output[j] = 0;
		}
		tmp>>=1;
		b--;
	}
}
int main(int argc,char* argv[]){

    startRandom();

    // control SNR step
    const double s_snr = -0.5;
    const double step = 0.02;
    const int snr_size = 500;

    // control the certain Frame and the bp
    int frame = 2;
    int t_lvl = 0;
    double _snr = 0;
    if(argc >= 3 )
        _snr = strtod(argv[2],NULL);

    if(argc >= 4)
        frame = strtod(argv[3],NULL);

    if(argc >= 5)
        t_lvl = strtod(argv[4],NULL);

    // for video encode
    const int puncture = 0;                     // puncture or not
    const double rate = 1/(double)(2-puncture);       // code rate
    const double a = 1;                         // Fading amplitude. a=1 -> AWGN channel
    double EbN0,L_c,sigma;

    // for basical info
    char buffer[50];
    const int h = __HEIGHT, w = __WIDTH, f = frame+1 ;
    const int lm = h*w;
    const int lu = lm+(G_L-1);
    int ** G = getGenerator();
    double * Ly = (double*) malloc(sizeof(double)*2*lu);
    int*** Y = new3d<int>(f,h,w);
    int* map_out = (int*) malloc(sizeof(int)*lm);

    double* Lu = (double*) malloc(sizeof(double)*lu);
    for(int i=0; i<lu ;++i)
        Lu[i] = 0;

    // pstate, pout
    const int Ns = pow(2,G_L-1);
    int ** pout = new2d<int>(Ns,4);
    int ** pstate = new2d<int>(Ns,2) ;
    double* Le1 = (double*)malloc(sizeof(double)*lu);
    double* Le2 = (double*)malloc(sizeof(double)*lu);

    trellis(G,G_N,G_L,Ns,pout,pstate);

    // frame buffer
    int*** imgr_bp = new3d<int>(PXL,h,w);
    double** Lu_c = new2d<double>(PXL,lu);  //channel decoder output

    // buffer for Ia, Ie
    double* Le = (double*) malloc(sizeof(double)*lm);
    double* Ia_pc = (double*) malloc(sizeof(double)*snr_size);
    double* Ie_pc = (double*) malloc(sizeof(double)*snr_size);
    int idx = 0;
    double tmp_sum = 0, tmp ;

    // read YUV
    sprintf(buffer,"%s_cif.yuv",argv[1]);
    yuv_read(buffer,h,w,f,Y,NULL,NULL);

//  video_encode(Y,f,h,w,_snr,G,Ly,map_out) for frame and t_lvl
    EbN0 = pow(10,_snr/10);      // convert Eb/N0[dB] to normal number
    L_c = 4*a*EbN0*rate;           // reliability value of the channel
    sigma = 1/sqrt(2*rate*EbN0);   // standard deviation of AWGN noise

    int* x = (int*) malloc(sizeof(int)*2*lu);
    img2bp_frame(Y[frame],h,w,imgr_bp);
    random_sequence(0,lm-1,map_out);
    rsc_encode(G,G_L,imgr_bp[t_lvl],map_out,w,lm,1,x);

    for(int i = 0 ; i < 2*lu ; ++i)
        Ly[i] = 0.5*L_c*((2*x[i] - 1)+ sigma*gaussian_noise());

    printf("processing ...%2.2f%%\n",0);
    for(double snr = s_snr; idx < snr_size ; snr+=step, idx++ , tmp_sum=0){
        printf("\tprocessing ...%2.2f%%\n",100*(snr-s_snr)/step/snr_size);
        // encode
        EbN0 = pow(10,snr/10);      // convert Eb/N0[dB] to normal number
        L_c = 4*a*EbN0*rate;           // reliability value of the channel
        sigma = 1/sqrt(2*rate*EbN0);   // standard deviation of AWGN noise

//        img2bp_frame(Y[frame],h,w,imgr_bp);
        for(int i = 0 ; i < lm ; ++i){
            tmp = (2*imgr_bp[t_lvl][map_out[i]/w][map_out[i]%w] - 1);
            Lu[i] = 0.5*L_c*( tmp + sigma*gaussian_noise());
            tmp_sum+=log2(1 + exp(-Lu[i]*tmp));
        }

        Ia_pc[idx] = 1 - tmp_sum/lm;

        // decode
        computeLe(Lu,Le1,Le2,lu);
        logmap(Ns, lu, 1, Ly, Le1, Le2, pstate, pout, Lu_c[t_lvl]);

        for(int i = 0 ; i < lm ; ++i)
            Le[map_out[i]] = Lu_c[t_lvl][i] - Lu[i];

        tmp_sum = 0;
        for(int i=0; i < lm ; ++i)
            tmp_sum+=log2(1 + exp(-Le[i]*(2*imgr_bp[t_lvl][i/w][i%w]-1)));

        Ie_pc[idx] = 1 - tmp_sum/lm;

    }
    printf("\r100%% completed!\n");

    FILE *file = fopen("output/exit_curve_pc.txt","a+");

    fprintf(file,"============================\n%s:SNR=%lf, frame#%d,bp#%d\nIa=\n",argv[1],_snr,frame+1,t_lvl+1);
    for(int i = 0 ; i < snr_size ; ++i)
        fprintf(file,"%lf,",Ia_pc[i]);
    fprintf(file,"\nIe=\n");
    for(int i = 0 ; i < snr_size ; ++i)
        fprintf(file,"%lf,",Ie_pc[i]);
    fprintf(file,"\n\n");

    fclose(file);

    write_pc_for_matlab(Ia_pc,Ie_pc,snr_size);

    // free memory
    free(Ly);
    free(map_out);
    delete2d<int>(G);
    deleteY(Y);

    delete3d<int>(imgr_bp);
    delete2d<double>(Lu_c);
    delete2d<int>(pstate);
    delete2d<int>(pout);

    free(Le);
    free(Lu);
    free(Le1);
    free(Le2);

    free(Ia_pc);
    free(Ie_pc);
    free(x);
}