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 selector. If not, see <http://www.gnu.org/licenses/>.
31 char *next_word(char *buffer, char *r, int buffer_size) {
36 while((*r == ' ') || (*r == '\t') || (*r == ',')) r++;
39 while((*r != '"') && (*r != '\0') &&
40 (s<buffer+buffer_size-1))
44 while((*r != '\r') && (*r != '\n') && (*r != '\0') &&
45 (*r != '\t') && (*r != ' ') && (*r != ',')) {
46 if(s == buffer + buffer_size) {
47 cerr << "Buffer overflow in next_word." << endl;
54 while((*r == ' ') || (*r == '\t') || (*r == ',')) r++;
55 if((*r == '\0') || (*r=='\r') || (*r=='\n')) r = 0;
62 scalar_t discrete_entropy(int *n, int nb) {
63 scalar_t s = 0, t = 0;
64 for(int k = 0; k < nb; k++) if(n[k] > 0) {
65 s += n[k] * log(scalar_t(n[k]));
68 return (log(t) - s/scalar_t(t))/log(2.0);
71 void random_permutation(int *val, int nb) {
72 for(int k = 0; k < nb; k++) val[k] = k;
74 for(int k = 0; k < nb - 1; k++) {
75 i = int(drand48() * (nb - k)) + k;
82 void tag_subset(bool *val, int nb_total, int nb_to_tag) {
83 ASSERT(nb_to_tag <= nb_total);
85 random_permutation(index, nb_total);
86 for(int n = 0; n < nb_total; n++) val[n] = false;
87 for(int n = 0; n < nb_to_tag; n++) val[index[n]] = true;
90 int compare_couple(const void *a, const void *b) {
91 if(((Couple *) a)->value < ((Couple *) b)->value) return -1;
92 else if(((Couple *) a)->value > ((Couple *) b)->value) return 1;