1 | #ifndef _theplu_yat_classifier_sv_index_ |
---|
2 | #define _theplu_yat_classifier_sv_index_ |
---|
3 | |
---|
4 | // $Id: SVindex.h 706 2006-12-19 08:59:19Z jari $ |
---|
5 | |
---|
6 | /* |
---|
7 | Copyright (C) The authors contributing to this file. |
---|
8 | |
---|
9 | This file is part of the yat library, http://lev.thep.lu.se/trac/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 2 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 this program; if not, write to the Free Software |
---|
23 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
---|
24 | 02111-1307, USA. |
---|
25 | */ |
---|
26 | |
---|
27 | #include "yat/utility/vector.h" |
---|
28 | |
---|
29 | #include <cassert> |
---|
30 | #include <vector> |
---|
31 | |
---|
32 | namespace theplu { |
---|
33 | namespace yat { |
---|
34 | namespace classifier { |
---|
35 | |
---|
36 | #ifndef DOXYGEN_SHOULD_SKIP_THIS |
---|
37 | /// @internal Class keeping track of which samples are support vectors and |
---|
38 | /// not. The first nof_sv elements in the vector are indices of the |
---|
39 | /// support vectors |
---|
40 | /// |
---|
41 | class SVindex |
---|
42 | { |
---|
43 | |
---|
44 | public: |
---|
45 | //Default Contructor |
---|
46 | SVindex(); |
---|
47 | |
---|
48 | // |
---|
49 | SVindex(const size_t); |
---|
50 | |
---|
51 | // @return index_first |
---|
52 | inline size_t index_first(void) const { return index_first_; } |
---|
53 | |
---|
54 | // @return index_second |
---|
55 | inline size_t index_second(void) const { return index_second_; } |
---|
56 | |
---|
57 | // synch the object against alpha |
---|
58 | void init(const utility::vector& alpha, const double); |
---|
59 | |
---|
60 | // @return nof samples |
---|
61 | inline size_t size(void) const { return vec_.size(); } |
---|
62 | |
---|
63 | // @return nof support vectors |
---|
64 | inline size_t nof_sv(void) const { return nof_sv_; } |
---|
65 | |
---|
66 | // making first to an nsv. If already sv, nothing happens. |
---|
67 | void nsv_first(void); |
---|
68 | |
---|
69 | // making second to an nsv. If already sv, nothing happens. |
---|
70 | void nsv_second(void); |
---|
71 | |
---|
72 | // randomizes the nsv part of vector and sets index_first to |
---|
73 | // nof_sv_ (the first nsv) |
---|
74 | void shuffle(void); |
---|
75 | |
---|
76 | // making first to a sv. If already sv, nothing happens. |
---|
77 | void sv_first(void); |
---|
78 | |
---|
79 | // making second to a sv. If already sv, nothing happens. |
---|
80 | void sv_second(void); |
---|
81 | |
---|
82 | // |
---|
83 | void update_first(const size_t); |
---|
84 | |
---|
85 | // |
---|
86 | void update_second(const size_t); |
---|
87 | |
---|
88 | // @return value_first |
---|
89 | inline size_t value_first(void) const { return value_first_; } |
---|
90 | |
---|
91 | // @return const ref value_second |
---|
92 | inline size_t value_second(void) const { return value_second_; } |
---|
93 | |
---|
94 | inline size_t operator()(size_t i) const { return vec_[i]; } |
---|
95 | |
---|
96 | private: |
---|
97 | size_t index_first_; |
---|
98 | size_t index_second_; |
---|
99 | size_t nof_sv_; |
---|
100 | std::vector<size_t> vec_; |
---|
101 | size_t value_first_; // vec_[index_first_] exists for fast access |
---|
102 | size_t value_second_; // vec_[index_second_] exists for fast access |
---|
103 | |
---|
104 | }; |
---|
105 | #endif /* DOXYGEN_SHOULD_SKIP_THIS */ |
---|
106 | |
---|
107 | }}} // of namespace classifier, yat, and theplu |
---|
108 | |
---|
109 | #endif |
---|