2 //////////////////////////////////////////////////////////////////////////////////
3 // This program is free software: you can redistribute it and/or modify //
4 // it under the terms of the version 3 of the GNU General Public License //
5 // as published by the Free Software Foundation. //
7 // This program is distributed in the hope that it will be useful, but //
8 // WITHOUT ANY WARRANTY; without even the implied warranty of //
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU //
10 // General Public License for more details. //
12 // You should have received a copy of the GNU General Public License //
13 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
15 // Written by Francois Fleuret //
16 // Copyright (C) Ecole Polytechnique Federale de Lausanne //
17 // Contact <francois.fleuret@epfl.ch> for comments & bug reports //
18 //////////////////////////////////////////////////////////////////////////////////
20 // $Id: fastentropy.h,v 1.3 2007-08-23 08:36:50 fleuret Exp $
27 // Lookup tables to speed up the training
29 extern int fe_nb_bits[65536];
30 extern double fe_logn[65536], fe_nlogn[65536];
32 void fe_init_tables();
34 inline void fe_set_bit(int k, uint32_t *a, int v) {
35 if(v) a[k/32] = a[k/32] | (1 << (k%32));
36 else a[k/32] = a[k/32] & ~(1 << (k%32));
39 inline int fe_get_bit(int k, uint32_t *a) {
40 return a[k/32] & (1 << (k%32));
43 inline int fe_count_and(int n, uint32_t *a, uint32_t *b) {
44 uint16_t *aa = (uint16_t *) a, *bb = (uint16_t *) b;
46 for(int k = 0; k < n/16; k++) t += fe_nb_bits[*aa++ & *bb++];
47 if(n%16 > 0) t += fe_nb_bits[(65535 >> (16-(n%16))) & *aa & *bb];
51 inline int fe_count_and_not(int n, uint32_t *a, uint32_t *b) {
52 uint16_t *aa = (uint16_t *) a, *bb = (uint16_t *) b;
54 for(int k = 0; k < n/16; k++) t += fe_nb_bits[*aa++ & ~*bb++];
55 if(n%16 > 0) t += fe_nb_bits[(65535 >> (16-(n%16))) & *aa & ~*bb];
59 inline int fe_count_and_not_not(int n, uint32_t *a, uint32_t *b) {
60 uint16_t *aa = (uint16_t *) a, *bb = (uint16_t *) b;
62 for(int k = 0; k < n/16; k++) t += fe_nb_bits[65535 & ~*aa++ & ~*bb++];
63 if(n%16 > 0) t += fe_nb_bits[(65535 >> (16-(n%16))) & ~*aa & ~*bb];
67 // This selection maximises the conditional mutual information between
68 // the features and the class to predict, given any feature already
69 // picked. Call fe_init_tables() beforehand.
71 void fe_selection_cmim(int nb_samples,
72 int nb_total_features, uint32_t **x, uint32_t *y,
73 int nb_selected, int *selected);
75 // This selection maximises the mutual information between the
76 // features and the class to predict, without taking care of the
77 // redundancy. Call fe_init_tables() beforehand.
79 void fe_selection_mim(int nb_samples,
80 int nb_total_features, uint32_t **x, uint32_t *y,
81 int nb_selected, int *selected);