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