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, (C) IDIAP //
16 // Contact <francois.fleuret@idiap.ch> for comments & bug reports //
17 ///////////////////////////////////////////////////////////////////////////
19 #include "sample_set.h"
21 SampleSet::SampleSet(int nb_features, int nb_samples) {
22 _nb_features = nb_features;
23 _nb_samples = nb_samples;
24 _shared_feature_values = new SharedResponses(_nb_features, _nb_samples);
25 _shared_feature_values->grab();
27 _labels = new int[_nb_samples];
28 _feature_values = new scalar_t *[_nb_samples];
29 for(int s = 0; s < _nb_samples; s++)
30 _feature_values[s] = _shared_feature_values->_responses + _nb_features * s;
34 SampleSet::SampleSet(SampleSet *father, int nb, int *indexes) {
35 _nb_features = father->_nb_features;
37 _shared_feature_values = father->_shared_feature_values;
38 _shared_feature_values->grab();
40 _labels = new int[_nb_samples];
41 _feature_values = new scalar_t *[_nb_samples];
42 for(int s = 0; s < _nb_samples; s++) {
43 _feature_values[s] = father->_feature_values[indexes[s]];
44 _labels[s] = father->_labels[indexes[s]];
48 SampleSet::~SampleSet() {
49 _shared_feature_values->release();
50 delete[] _feature_values;
54 void SampleSet::set_sample(int n,
55 PiFeatureFamily *pi_feature_family,
57 PoseCell *cell, int label) {
58 ASSERT(n >= 0 && n < _nb_samples);
60 PiReferential referential(cell);
61 for(int f = 0; f < _nb_features; f++) {
62 _feature_values[n][f] = pi_feature_family->get_feature(f)->response(image, &referential);
63 ASSERT(!isnan(_feature_values[n][f]));