2 * folded-ctf is an implementation of the folded hierarchy of
3 * classifiers for object detection, developed by Francois Fleuret
6 * Copyright (c) 2008 Idiap Research Institute, http://www.idiap.ch/
7 * Written by Francois Fleuret <francois.fleuret@idiap.ch>
9 * This file is part of folded-ctf.
11 * folded-ctf is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published
13 * by the Free Software Foundation, either version 3 of the License,
14 * or (at your option) any later version.
16 * folded-ctf is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with folded-ctf. If not, see <http://www.gnu.org/licenses/>.
28 A bunch of useful little functions.
44 //typedef double scalar_t;
45 typedef float scalar_t;
46 const scalar_t SCALAR_MAX = FLT_MAX;
47 const scalar_t SCALAR_MIN = FLT_MIN;
49 const int buffer_size = 1024;
50 const int large_buffer_size = 65536;
55 #define ASSERT(x) if(!(x)) { \
56 std::cerr << "ASSERT FAILED IN " << __FILE__ << ":" << __LINE__ << endl; \
64 T smooth_min(T x, T y) {
66 return 0.5 * (x + y - (x - y)/(1 + 1/z) - (y - x)/(1 + z));
70 void write_var(ostream *os, const T *x) { os->write((char *) x, sizeof(T)); }
73 void read_var(istream *is, T *x) { is->read((char *) x, sizeof(T)); }
76 void grow(int *nb_max, int nb, T** current, int factor) {
79 T *tmp = new T[*nb_max * factor];
80 memcpy(tmp, *current, *nb_max * sizeof(T));
92 inline scalar_t log2(scalar_t x) {
93 return log(x)/log(2.0);
96 inline scalar_t xi(scalar_t x) {
97 if(x <= 0.0) return 0.0;
98 else return - x * log(x)/log(2.0);
101 scalar_t discrete_entropy(int *n, int nb);
103 char *basename(char *name);
105 char *next_word(char *buffer, char *r, int buffer_size);
107 void random_permutation(int *val, int nb);
108 void tag_subset(bool *val, int nb_total, int nb_to_tag);
115 int compare_couple(const void *a, const void *b);
117 // size total program size
118 // resident resident set size
119 // share shared pages
123 // dt dirty pages (unused in Linux 2.6)
125 void used_memory(size_t &size, size_t &resident,
126 size_t &share, size_t &text, size_t &lib, size_t &data,