void ef_enumeration_benchmark(uint64_t m, uint8_t bits) { succinct::elias_fano::elias_fano_builder bvb(uint64_t(1) << bits, m); monotone_generator mgen(m, bits, 37); for (size_t i = 0; i < m; ++i) { bvb.push_back(mgen.next()); } assert(mgen.done()); succinct::elias_fano ef(&bvb); succinct::mapper::size_tree_of(ef)->dump(); double elapsed; uint64_t foo = 0; SUCCINCT_TIMEIT(elapsed) { succinct::elias_fano::select_enumerator it(ef, 0); for (size_t i = 0; i < m; ++i) { foo ^= it.next(); } } volatile uint64_t vfoo = foo; (void)vfoo; // silence warning std::cerr << "Elapsed: " << elapsed / 1000 << " msec\n" << double(m) / elapsed << " Mcodes/s" << std::endl; }
// RANSAC // // Given a list of data points, find the parameters of a model that fits to // those points. Several models are tried, and the model with the highest // number of inliers is kept. // // A basic idea of this kind of ransac is that a maximum allowed error is fixed // by hand, and then the inliers of a model are defined as the data points // which fit the model up to the allowed error. The RANSAC algorithm randomly // tries several models and keeps the one with the largest number of inliers. int ransac( // output //int *out_ninliers, // number of inliers bool *out_mask, // array mask identifying the inliers float *out_model, // model parameters // input data float *data, // array of input data // input context int datadim, // dimension of each data point int n, // number of data points int modeldim, // number of model parameters ransac_error_evaluation_function *mev, ransac_model_generating_function *mgen, int nfit, // data points needed to produce a model // input parameters int ntrials, // number of models to try int min_inliers, // minimum allowed number of inliers float max_error, // maximum allowed error // decoration ransac_model_accepting_function *macc, void *usr ) { fprintf(stderr, "running RANSAC over %d datapoints of dimension %d\n", n, datadim); fprintf(stderr, "will try to find a model of size %d from %d points\n", modeldim, nfit); fprintf(stderr, "we will make %d trials and keep the best with e<%g\n", ntrials, max_error); fprintf(stderr, "a model must have more than %d inliers\n", min_inliers); mt_init((unsigned long int) 0); // fix seed for the Mersenne Twister PRNG int best_ninliers = 0; float best_model[modeldim]; bool *best_mask = xmalloc(n * sizeof*best_mask); bool *tmp_mask = xmalloc(n * sizeof*best_mask); for (int i = 0; i < ntrials; i++) { int indices[nfit]; fill_random_indices(indices, nfit, 0, n); float x[nfit*datadim]; for (int j = 0; j < nfit; j++) for (int k = 0; k < datadim; k++) x[datadim*j + k] = data[datadim*indices[j] + k]; float model[modeldim*MAX_MODELS]; int nm = mgen(model, x, usr); if (!nm) continue; if (macc && !macc(model, usr)) continue; // generally, nm=1 for (int j = 0; j < nm; j++) { float *modelj = model + j*modeldim; int n_inliers = ransac_trial(tmp_mask, data, modelj, max_error, datadim, n, mev, usr); if (n_inliers > best_ninliers) { best_ninliers = n_inliers; for(int k = 0; k < modeldim; k++) best_model[k] = modelj[k]; for(int k = 0; k < n; k++) best_mask[k] = tmp_mask[k]; } } } fprintf(stderr, "RANSAC found this best model:"); for (int i = 0; i < modeldim; i++) fprintf(stderr, " %g", best_model[i]); fprintf(stderr, "\n"); if (0) { FILE *f = xfopen("/tmp/ramo.txt", "w"); for (int i = 0; i < modeldim; i++) fprintf(f,"%lf%c",best_model[i],i==modeldim-1?'\n':' '); xfclose(f); } //fprintf(stderr, "errors of outliers:"); //for (int i = 0; i < n; i++) // if (!best_mask[i]) { // float e = mev(best_model, data+i*datadim, usr); // fprintf(stderr, " %g", e); // } //fprintf(stderr, "\n"); //fprintf(stderr, "errors of inliers:"); //for (int i = 0; i < n; i++) // if (best_mask[i]) { // float e = mev(best_model, data+i*datadim, usr); // fprintf(stderr, " %g", e); // } //fprintf(stderr, "\n"); //fprintf(stderr, "errors of data points:\n"); //for (int i = 0; i < n; i++) { // float e = mev(best_model, data+i*datadim, usr); // fprintf(stderr, "\t%g\t%s\n", e, best_mask[i]?"GOOD":"bad"); //} int return_value = 0; if (best_ninliers >= min_inliers) { return_value = best_ninliers; } else return_value = 0; for (int j = 0; j < modeldim; j++) if (!isfinite(best_model[j])) fail("model_%d not finite", j); if (out_model) for(int j = 0; j < modeldim; j++) out_model[j] = best_model[j]; if (out_mask) for(int j = 0; j < n; j++) out_mask[j] = best_mask[j]; free(best_mask); free(tmp_mask); return return_value; }