source: trunk/yat/classifier/SVindex.h @ 2986

Last change on this file since 2986 was 2986, checked in by Peter, 10 years ago

merge 0.10-stable branch into trunk

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.7 KB
Line 
1#ifndef _theplu_yat_classifier_sv_index_
2#define _theplu_yat_classifier_sv_index_
3
4// $Id: SVindex.h 2986 2013-02-18 08:07:44Z peter $
5
6/*
7  Copyright (C) 2006, 2007, 2008 Jari Häkkinen, Peter Johansson
8  Copyright (C) 2013 Jari Häkkinen
9
10  This file is part of the yat library, http://dev.thep.lu.se/yat
11
12  The yat library is free software; you can redistribute it and/or
13  modify it under the terms of the GNU General Public License as
14  published by the Free Software Foundation; either version 3 of the
15  License, or (at your option) any later version.
16
17  The yat library is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  General Public License for more details.
21
22  You should have received a copy of the GNU General Public License
23  along with yat. If not, see <http://www.gnu.org/licenses/>.
24*/
25
26#include <cstddef>
27#include <vector>
28
29namespace theplu {
30namespace yat {
31
32namespace utility {
33  class Vector;
34}
35
36namespace classifier { 
37
38  ///
39  /// \internal
40  ///
41  /// Internal Class keeping track of which samples are support vectors and
42  /// not. The first nof_sv elements in the vector are indices of the
43  /// support vectors
44  ///
45  class SVindex
46  {
47
48  public:
49    ///Default Contructor
50    SVindex(); 
51
52    /// Constructor
53    SVindex(const size_t);
54
55    /// @return index_first
56    size_t index_first(void) const;
57
58    /// @return index_second
59    size_t index_second(void) const;
60
61    /// synch the object against alpha
62    void init(const utility::Vector& alpha, const double);
63
64    /// @return nof support vectors
65    size_t nof_sv(void) const;
66
67    /// making first to an nsv. If already sv, nothing happens.
68    void nsv_first(void);
69
70    /// making second to an nsv. If already sv, nothing happens.
71    void nsv_second(void);   
72
73    /// randomizes the nsv part of vector and sets index_first to
74    /// nof_sv_ (the first nsv)
75    void shuffle(void);
76
77    /// @return nof samples
78    size_t size(void) const;
79
80    /// making first to a sv. If already sv, nothing happens.
81    void sv_first(void);
82
83    /// making second to a sv. If already sv, nothing happens.
84    void sv_second(void);
85
86    /// set index_first to \a i
87    void update_first(const size_t i);
88
89    /// set index_second to \a i
90    void update_second(const size_t i);
91
92    /// @return value_first
93    size_t value_first(void) const;
94
95    /// @return value_second
96    size_t value_second(void) const;
97
98    /// \return index \a i (if i<nof_sv() index is sv)
99    size_t operator()(size_t i) const;
100
101  private:
102    size_t index_first_;
103    size_t index_second_;
104    size_t nof_sv_;
105    std::vector<size_t> vec_;
106    size_t value_first_; // vec_[index_first_] exists for fast access
107    size_t value_second_; // vec_[index_second_] exists for fast access
108   
109  };
110
111}}} // of namespace classifier, yat, and theplu
112
113#endif
Note: See TracBrowser for help on using the repository browser.