Last change
on this file since 642 was
642,
checked in by Peter, 16 years ago
|
adding class for selecting features by random
|
File size:
1.1 KB
|
Line | |
---|
1 | // $Id$ |
---|
2 | |
---|
3 | #include "FeatureSelectorRandom.h" |
---|
4 | #include "MatrixLookup.h" |
---|
5 | #include "MatrixLookupWeighted.h" |
---|
6 | #include "Target.h" |
---|
7 | #include "c++_tools/random/random.h" |
---|
8 | |
---|
9 | #include <algorithm> |
---|
10 | |
---|
11 | namespace theplu { |
---|
12 | namespace classifier { |
---|
13 | |
---|
14 | |
---|
15 | FeatureSelectorRandom::FeatureSelectorRandom(size_t N) |
---|
16 | : FeatureSelector(N) |
---|
17 | { |
---|
18 | } |
---|
19 | |
---|
20 | |
---|
21 | |
---|
22 | void FeatureSelectorRandom::update(const MatrixLookup& data, |
---|
23 | const Target& target) |
---|
24 | { |
---|
25 | assert(data.columns()==target.size()); |
---|
26 | update(data.rows()); |
---|
27 | } |
---|
28 | |
---|
29 | |
---|
30 | void FeatureSelectorRandom::update(const MatrixLookupWeighted& data, |
---|
31 | const Target& target) |
---|
32 | { |
---|
33 | assert(data.columns()==target.size()); |
---|
34 | update(data.rows()); |
---|
35 | } |
---|
36 | |
---|
37 | |
---|
38 | void FeatureSelectorRandom::update(size_t total_N) |
---|
39 | { |
---|
40 | features_.resize(0); |
---|
41 | features_.reserve(total_N); |
---|
42 | for (size_t i=0; i<total_N; ++i) |
---|
43 | features_.push_back(i); |
---|
44 | random::DiscreteUniform rnd; |
---|
45 | // Peter should use random_sample here, but not included in std |
---|
46 | std::random_shuffle(features_.begin(), features_.end(), rnd); |
---|
47 | features_.resize(N_); |
---|
48 | } |
---|
49 | |
---|
50 | |
---|
51 | } // end of namespace classifier |
---|
52 | } // end of namespace theplu |
---|
Note: See
TracBrowser
for help on using the repository browser.