X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=sample_set.cc;fp=sample_set.cc;h=bf323e641196e0e97175e3433c753e8c8ff4d0ee;hb=d922ad61d35e9a6996730bec24b16f8bf7bc426c;hp=0000000000000000000000000000000000000000;hpb=3bb118f5a9462d02ff7d99ef28ecc0d7e23529f9;p=folded-ctf.git diff --git a/sample_set.cc b/sample_set.cc new file mode 100644 index 0000000..bf323e6 --- /dev/null +++ b/sample_set.cc @@ -0,0 +1,65 @@ + +/////////////////////////////////////////////////////////////////////////// +// This program is free software: you can redistribute it and/or modify // +// it under the terms of the version 3 of the GNU General Public License // +// as published by the Free Software Foundation. // +// // +// This program is distributed in the hope that it will be useful, but // +// WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // +// General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +// // +// Written by Francois Fleuret, (C) IDIAP // +// Contact for comments & bug reports // +/////////////////////////////////////////////////////////////////////////// + +#include "sample_set.h" + +SampleSet::SampleSet(int nb_features, int nb_samples) { + _nb_features = nb_features; + _nb_samples = nb_samples; + _shared_feature_values = new SharedResponses(_nb_features, _nb_samples); + _shared_feature_values->grab(); + + _labels = new int[_nb_samples]; + _feature_values = new scalar_t *[_nb_samples]; + for(int s = 0; s < _nb_samples; s++) + _feature_values[s] = _shared_feature_values->_responses + _nb_features * s; + +} + +SampleSet::SampleSet(SampleSet *father, int nb, int *indexes) { + _nb_features = father->_nb_features; + _nb_samples = nb; + _shared_feature_values = father->_shared_feature_values; + _shared_feature_values->grab(); + + _labels = new int[_nb_samples]; + _feature_values = new scalar_t *[_nb_samples]; + for(int s = 0; s < _nb_samples; s++) { + _feature_values[s] = father->_feature_values[indexes[s]]; + _labels[s] = father->_labels[indexes[s]]; + } +} + +SampleSet::~SampleSet() { + _shared_feature_values->release(); + delete[] _feature_values; + delete[] _labels; +} + +void SampleSet::set_sample(int n, + PiFeatureFamily *pi_feature_family, + RichImage *image, + PoseCell *cell, int label) { + ASSERT(n >= 0 && n < _nb_samples); + _labels[n] = label; + PiReferential referential(cell); + for(int f = 0; f < _nb_features; f++) { + _feature_values[n][f] = pi_feature_family->get_feature(f)->response(image, &referential); + ASSERT(!isnan(_feature_values[n][f])); + } +}