2 * svrt is the ``Synthetic Visual Reasoning Test'', an image
3 * generator for evaluating classification performance of machine
4 * learning systems, humans and primates.
6 * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/
7 * Written by Francois Fleuret <francois.fleuret@idiap.ch>
9 * This file is part of svrt.
11 * svrt is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License version 3 as
13 * published by the Free Software Foundation.
15 * svrt is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with svrt. If not, see <http://www.gnu.org/licenses/>.
27 #include "fusion_sort.h"
29 scalar_t robust_sampling(int nb, scalar_t *weights, int nb_to_sample, int *sampled) {
32 for(int k = 0; k < nb_to_sample; k++) sampled[k] = 0;
35 scalar_t *pair_weights = new scalar_t[(nb+1)/2];
36 for(int k = 0; k < nb/2; k++)
37 pair_weights[k] = weights[2 * k] + weights[2 * k + 1];
39 pair_weights[(nb+1)/2 - 1] = weights[nb-1];
40 scalar_t result = robust_sampling((nb+1)/2, pair_weights, nb_to_sample, sampled);
41 for(int k = 0; k < nb_to_sample; k++) {
43 // There is a bit of a trick for the isolated sample in the odd
44 // case. Since the corresponding pair weight is the same as the
45 // one sample alone, the test is always true and the isolated
46 // sample will be taken for sure.
47 if(drand48() * pair_weights[s] <= weights[2 * s])
50 sampled[k] = 2 * s + 1;
52 delete[] pair_weights;