yat  0.12.3pre
IGP.h
1 #ifndef _theplu_yat_classifier_igp_
2 #define _theplu_yat_classifier_igp_
3 
4 // $Id: IGP.h 2384 2010-12-22 14:03:36Z peter $
5 
6 /*
7  Copyright (C) 2006 Jari Häkkinen, Markus Ringnér
8  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson, Markus Ringnér
9  Copyright (C) 2009, 2010 Peter Johansson
10 
11  This file is part of the yat library, http://dev.thep.lu.se/yat
12 
13  The yat library is free software; you can redistribute it and/or
14  modify it under the terms of the GNU General Public License as
15  published by the Free Software Foundation; either version 3 of the
16  License, or (at your option) any later version.
17 
18  The yat library is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  General Public License for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with yat. If not, see <http://www.gnu.org/licenses/>.
25 */
26 
27 #include "MatrixLookup.h"
28 #include "Target.h"
29 #include "yat/utility/concept_check.h"
30 #include "yat/utility/Vector.h"
31 #include "yat/utility/yat_assert.h"
32 
33 #include <boost/concept_check.hpp>
34 
35 #include <cmath>
36 #include <limits>
37 #include <stdexcept>
38 
39 namespace theplu {
40 namespace yat {
41 namespace classifier {
42 
43  class Target;
44  class MatrixLookup;
45 
51  template <typename Distance>
52  class IGP
53  {
54 
55  public:
60  IGP(const MatrixLookup&, const Target&);
61 
62 
67  IGP(const MatrixLookup&, const Target&, const Distance&);
68 
72  virtual ~IGP();
73 
77  const utility::Vector& score(void) const;
78 
79 
80  private:
81  void calculate();
82 
83  utility::Vector igp_;
84  Distance distance_;
85 
86  const MatrixLookup& matrix_;
87  const Target& target_;
88  };
89 
90 
91  // templates
92 
93  template <typename Distance>
94  IGP<Distance>::IGP(const MatrixLookup& data, const Target& target)
95  : matrix_(data), target_(target)
96  {
97  BOOST_CONCEPT_ASSERT((utility::DistanceConcept<Distance>));
98  calculate();
99  }
100 
101  template <typename Distance>
102  IGP<Distance>::IGP(const MatrixLookup& data, const Target& target, const Distance& dist)
103  : matrix_(data), target_(target), distance_(dist)
104  {
105  BOOST_CONCEPT_ASSERT((utility::DistanceConcept<Distance>));
106  calculate();
107  }
108 
109 
110  template <typename Distance>
112  {
113  }
114 
115  template <typename Distance>
117  {
118  YAT_ASSERT(target_.size()==matrix_.columns());
119 
120  // Calculate IGP for each class
121  igp_ = utility::Vector(target_.nof_classes());
122 
123  for(size_t i=0; i<target_.size(); i++) {
124  size_t neighbor=i;
125  double mindist=std::numeric_limits<double>::max();
126  for(size_t j=0; j<target_.size(); j++) {
127  if (i==j) // avoid self-self comparison
128  continue;
129  double dist = distance_(matrix_.begin_column(i), matrix_.end_column(i),
130  matrix_.begin_column(j));
131  if(dist<mindist) {
132  mindist=dist;
133  neighbor=j;
134  }
135  }
136  if(target_(i)==target_(neighbor))
137  igp_(target_(i))++;
138 
139  }
140  for(size_t i=0; i<target_.nof_classes(); i++) {
141  igp_(i)/=static_cast<double>(target_.size(i));
142  }
143  }
144 
145 
146  template <typename Distance>
148  {
149  return igp_;
150  }
151 
152 }}} // of namespace classifier, yat, and theplu
153 
154 #endif
General view into utility::Matrix.
Definition: MatrixLookup.h:70
Class for containing sample labels.
Definition: Target.h:47
IGP(const MatrixLookup &, const Target &)
Definition: IGP.h:94
Class for In Group Proportions (IGP)
Definition: IGP.h:52
virtual ~IGP()
Definition: IGP.h:111
T max(const T &a, const T &b, const T &c)
Definition: stl_utility.h:638
This is the yat interface to GSL vector.
Definition: Vector.h:57
const utility::Vector & score(void) const
Definition: IGP.h:147
Concept check for a Distance.
Definition: concept_check.h:273

Generated on Mon Jun 1 2015 12:29:51 for yat by  doxygen 1.8.5