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 version 3 as
13 * published by the Free Software Foundation.
15 * folded-ctf is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with folded-ctf. If not, see <http://www.gnu.org/licenses/>.
25 #include "sample_set.h"
27 SampleSet::SampleSet(int nb_features, int nb_samples) {
28 _nb_features = nb_features;
29 _nb_samples = nb_samples;
30 _shared_feature_values = new SharedResponses(_nb_features, _nb_samples);
31 _shared_feature_values->grab();
33 _labels = new int[_nb_samples];
34 _feature_values = new scalar_t *[_nb_samples];
35 for(int s = 0; s < _nb_samples; s++)
36 _feature_values[s] = _shared_feature_values->_responses + _nb_features * s;
40 SampleSet::SampleSet(SampleSet *father, int nb, int *indexes) {
41 _nb_features = father->_nb_features;
43 _shared_feature_values = father->_shared_feature_values;
44 _shared_feature_values->grab();
46 _labels = new int[_nb_samples];
47 _feature_values = new scalar_t *[_nb_samples];
48 for(int s = 0; s < _nb_samples; s++) {
49 _feature_values[s] = father->_feature_values[indexes[s]];
50 _labels[s] = father->_labels[indexes[s]];
54 SampleSet::~SampleSet() {
55 _shared_feature_values->release();
56 delete[] _feature_values;
60 void SampleSet::set_sample(int n,
61 PiFeatureFamily *pi_feature_family,
63 PoseCell *cell, int label) {
64 ASSERT(n >= 0 && n < _nb_samples);
66 PiReferential referential(cell);
67 for(int f = 0; f < _nb_features; f++) {
68 _feature_values[n][f] = pi_feature_family->get_feature(f)->response(image, &referential);
69 ASSERT(!isnan(_feature_values[n][f]));