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 // (C) Idiap Research Institute //
18 // Contact <francois.fleuret@idiap.ch> for comments & bug reports //
19 ///////////////////////////////////////////////////////////////////////////
21 #include "sample_set.h"
23 SampleSet::SampleSet(int nb_features, int nb_samples) {
24 _nb_features = nb_features;
25 _nb_samples = nb_samples;
26 _shared_feature_values = new SharedResponses(_nb_features, _nb_samples);
27 _shared_feature_values->grab();
29 _labels = new int[_nb_samples];
30 _feature_values = new scalar_t *[_nb_samples];
31 for(int s = 0; s < _nb_samples; s++)
32 _feature_values[s] = _shared_feature_values->_responses + _nb_features * s;
36 SampleSet::SampleSet(SampleSet *father, int nb, int *indexes) {
37 _nb_features = father->_nb_features;
39 _shared_feature_values = father->_shared_feature_values;
40 _shared_feature_values->grab();
42 _labels = new int[_nb_samples];
43 _feature_values = new scalar_t *[_nb_samples];
44 for(int s = 0; s < _nb_samples; s++) {
45 _feature_values[s] = father->_feature_values[indexes[s]];
46 _labels[s] = father->_labels[indexes[s]];
50 SampleSet::~SampleSet() {
51 _shared_feature_values->release();
52 delete[] _feature_values;
56 void SampleSet::set_sample(int n,
57 PiFeatureFamily *pi_feature_family,
59 PoseCell *cell, int label) {
60 ASSERT(n >= 0 && n < _nb_samples);
62 PiReferential referential(cell);
63 for(int f = 0; f < _nb_features; f++) {
64 _feature_values[n][f] = pi_feature_family->get_feature(f)->response(image, &referential);
65 ASSERT(!isnan(_feature_values[n][f]));