// $Id: FeatureSelectorRandom.cc 1392 2008-07-28 19:35:30Z peter $ /* Copyright (C) 2006, 2007 Jari Häkkinen, Peter Johansson Copyright (C) 2008 Peter Johansson This file is part of the yat library, http://dev.thep.lu.se/yat The yat library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. The yat library 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, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "FeatureSelectorRandom.h" #include "MatrixLookup.h" #include "MatrixLookupWeighted.h" #include "Target.h" #include "yat/random/random.h" #include #include namespace theplu { namespace yat { namespace classifier { FeatureSelectorRandom::FeatureSelectorRandom(size_t N) : FeatureSelector(N) { } void FeatureSelectorRandom::update(const MatrixLookup& data, const Target& target) { assert(data.columns()==target.size()); update(data.rows()); } void FeatureSelectorRandom::update(const MatrixLookupWeighted& data, const Target& target) { assert(data.columns()==target.size()); update(data.rows()); } void FeatureSelectorRandom::update(size_t total_N) { std::vector* features = new std::vector; features->reserve(total_N); for (size_t i=0; ipush_back(i); // Peter should use random_sample here, but not included in std random::random_shuffle(features->begin(), features->end()); features->resize(N_); features_ = utility::Index(utility::SmartPtr >(features)); } }}} // of namespace classifier, yat, and theplu