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

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

Addresses #436.

  • 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 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 this program; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23  02111-1307, USA.
24*/
25
26#include "FeatureSelectorIR.h"
27#include "FeatureSelector.h"
28#include "MatrixLookup.h"
29#include "MatrixLookupWeighted.h"
30#include "InputRanker.h"
31#include "Target.h"
32
33#include <algorithm>
34#include <cassert>
35
36namespace theplu {
37namespace yat {
38namespace classifier {
39
40
41  FeatureSelectorIR::FeatureSelectorIR(statistics::Score& score, size_t N, 
42                                       size_t first)
43    : FeatureSelector(N, first), score_(score)
44  {
45  }
46
47
48
49  FeatureSelectorIR::FeatureSelectorIR(const FeatureSelectorIR& other)
50    : FeatureSelector(other), score_(other.score_)
51  {
52  }
53
54
55
56  FeatureSelectorIR& FeatureSelectorIR::operator=(const FeatureSelectorIR& other)
57  {
58    FeatureSelector::operator=(other);
59    return *this;
60  }
61
62
63  void FeatureSelectorIR::update(const MatrixLookup& data, const Target& target)
64  {
65    assert(data.columns()==target.size());
66    InputRanker ir = InputRanker(data, target, score_);
67    std::vector<size_t>* features = new std::vector<size_t>(N_);
68    std::copy(ir.id().begin()+first_, ir.id().begin()+first_+N_,
69              features->begin());
70    features_ = 
71      utility::Index(utility::SmartPtr<const std::vector<size_t> >(features));
72  }
73
74
75  void FeatureSelectorIR::update(const MatrixLookupWeighted& data, 
76                                 const Target& target)
77  {
78    assert(data.columns()==target.size());
79    InputRanker ir = InputRanker(data, target, score_);
80    std::vector<size_t>* features = new std::vector<size_t>(N_);
81    std::copy(ir.id().begin()+first_, ir.id().begin()+first_+N_,
82              features->begin());
83    features_ = 
84      utility::Index(utility::SmartPtr<const std::vector<size_t> >(features));
85  }
86
87}}} // of namespace classifier, yat, and theplu
Note: See TracBrowser for help on using the repository browser.