source: trunk/yat/classifier/FeatureSelectorIR.cc @ 1580

Last change on this file since 1580 was 1487, checked in by Jari Häkkinen, 13 years ago

Addresses #436. GPL license copy reference should also be updated.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date ID
File size: 2.4 KB
Line 
1// $Id$
2
3/*
4  Copyright (C) 2006 Jari Häkkinen, Peter Johansson
5  Copyright (C) 2007 Jari Häkkinen, Peter Johansson, Markus Ringnér
6  Copyright (C) 2008 Peter Johansson
7
8  This file is part of the yat library, http://dev.thep.lu.se/yat
9
10  The yat library is free software; you can redistribute it and/or
11  modify it under the terms of the GNU General Public License as
12  published by the Free Software Foundation; either version 3 of the
13  License, or (at your option) any later version.
14
15  The yat library is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  General Public License for more details.
19
20  You should have received a copy of the GNU General Public License
21  along with yat. If not, see <http://www.gnu.org/licenses/>.
22*/
23
24#include "FeatureSelectorIR.h"
25#include "FeatureSelector.h"
26#include "MatrixLookup.h"
27#include "MatrixLookupWeighted.h"
28#include "InputRanker.h"
29#include "Target.h"
30
31#include <algorithm>
32#include <cassert>
33
34namespace theplu {
35namespace yat {
36namespace classifier {
37
38
39  FeatureSelectorIR::FeatureSelectorIR(statistics::Score& score, size_t N, 
40                                       size_t first)
41    : FeatureSelector(N, first), score_(score)
42  {
43  }
44
45
46
47  FeatureSelectorIR::FeatureSelectorIR(const FeatureSelectorIR& other)
48    : FeatureSelector(other), score_(other.score_)
49  {
50  }
51
52
53
54  FeatureSelectorIR& FeatureSelectorIR::operator=(const FeatureSelectorIR& other)
55  {
56    FeatureSelector::operator=(other);
57    return *this;
58  }
59
60
61  void FeatureSelectorIR::update(const MatrixLookup& data, const Target& target)
62  {
63    assert(data.columns()==target.size());
64    InputRanker ir = InputRanker(data, target, score_);
65    std::vector<size_t>* features = new std::vector<size_t>(N_);
66    std::copy(ir.id().begin()+first_, ir.id().begin()+first_+N_,
67              features->begin());
68    features_ = 
69      utility::Index(utility::SmartPtr<const std::vector<size_t> >(features));
70  }
71
72
73  void FeatureSelectorIR::update(const MatrixLookupWeighted& data, 
74                                 const Target& target)
75  {
76    assert(data.columns()==target.size());
77    InputRanker ir = InputRanker(data, target, score_);
78    std::vector<size_t>* features = new std::vector<size_t>(N_);
79    std::copy(ir.id().begin()+first_, ir.id().begin()+first_+N_,
80              features->begin());
81    features_ = 
82      utility::Index(utility::SmartPtr<const std::vector<size_t> >(features));
83  }
84
85}}} // of namespace classifier, yat, and theplu
Note: See TracBrowser for help on using the repository browser.