source: trunk/yat/classifier/FeatureSelectorIR.cc

Last change on this file was 2919, checked in by Peter, 9 years ago

update copyright years

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