source: trunk/yat/classifier/FeatureSelectorRandom.cc @ 831

Last change on this file since 831 was 831, checked in by Peter, 14 years ago

Refs #185.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 1.9 KB
Line 
1// $Id: FeatureSelectorRandom.cc 831 2007-03-27 13:22:09Z peter $
2
3/*
4  Copyright (C) 2006 Jari Häkkinen, Peter Johansson
5  Copyright (C) 2007 Peter Johansson
6
7  This file is part of the yat library, http://lev.thep.lu.se/trac/yat
8
9  The yat library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version.
13
14  The yat library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22  02111-1307, USA.
23*/
24
25#include "FeatureSelectorRandom.h"
26#include "MatrixLookup.h"
27#include "MatrixLookupWeighted.h"
28#include "Target.h"
29#include "yat/random/random.h"
30
31#include <algorithm>
32#include <cassert>
33
34namespace theplu {
35namespace yat {
36namespace classifier {
37
38
39  FeatureSelectorRandom::FeatureSelectorRandom(size_t N)
40    : FeatureSelector(N)
41  {
42  }
43
44
45
46  void FeatureSelectorRandom::update(const MatrixLookup& data, 
47                                     const Target& target)
48  {
49    assert(data.columns()==target.size());
50    update(data.rows());
51  }
52
53
54  void FeatureSelectorRandom::update(const MatrixLookupWeighted& data, 
55                                 const Target& target)
56  {
57    assert(data.columns()==target.size());
58    update(data.rows());
59  }
60
61
62  void FeatureSelectorRandom::update(size_t total_N)
63  {
64    features_.resize(0);
65    features_.reserve(total_N);
66    for (size_t i=0; i<total_N; ++i)
67      features_.push_back(i);
68    random::DiscreteUniform rnd;
69    // Peter should use random_sample here, but not included in std
70    std::random_shuffle(features_.begin(), features_.end(), rnd);
71    features_.resize(N_);
72  }
73
74}}} // of namespace classifier, yat, and theplu
Note: See TracBrowser for help on using the repository browser.