automatic commit
[folded-ctf.git] / sample_set.h
1
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.                         //
6 //                                                                       //
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.                              //
11 //                                                                       //
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/>.  //
14 //                                                                       //
15 // Written by Francois Fleuret                                           //
16 // (C) Idiap Research Institute                                          //
17 //                                                                       //
18 // Contact <francois.fleuret@idiap.ch> for comments & bug reports        //
19 ///////////////////////////////////////////////////////////////////////////
20
21 /*
22
23   A SampleSet stands for a set of samples from R^d with their
24   labels. It abstracts the notion features and is what the machine
25   learning techniques of this software see.
26
27  */
28
29 #ifndef SAMPLE_SET_H
30 #define SAMPLE_SET_H
31
32 #include "pose_cell.h"
33 #include "pi_feature_family.h"
34 #include "shared_responses.h"
35
36 class SampleSet {
37   int _nb_features;
38   int _nb_samples;
39   SharedResponses *_shared_feature_values;
40   scalar_t **_feature_values;
41   int *_labels;
42
43 public:
44
45   inline int nb_samples() { return _nb_samples; }
46   inline int nb_features() { return _nb_features; }
47
48   inline int label(int n_sample) {
49     ASSERT(n_sample >= 0 && n_sample < _nb_samples);
50     return _labels[n_sample];
51   }
52
53   inline scalar_t feature_value(int n_sample, int n_feature) {
54     ASSERT(n_sample >= 0 && n_sample < _nb_samples &&
55            n_feature >= 0 && n_feature < _nb_features);
56     ASSERT(!isnan(_feature_values[n_sample][n_feature]));
57     return _feature_values[n_sample][n_feature];
58   }
59
60   SampleSet(int nb_features, int nb_samples);
61   SampleSet(SampleSet *father, int nb, int *indexes);
62
63   ~SampleSet();
64
65   void set_sample(int n,
66                   PiFeatureFamily *pi_feature_family,
67                   RichImage *image,
68                   PoseCell *cell,
69                   int label);
70 };
71
72 #endif