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

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

Fixed #include statemenst and forward declarations. asserts in headers removed.

  • 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 757 2007-02-19 18:51:31Z 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 <vector>
28
29namespace theplu {
30namespace yat {
31
32namespace utility {
33  class vector;
34}
35
36namespace classifier { 
37
38#ifndef DOXYGEN_SHOULD_SKIP_THIS
39  /// @internal Class keeping track of which samples are support vectors and
40  /// not. The first nof_sv elements in the vector are indices of the
41  /// support vectors
42  ///
43  class SVindex
44  {
45
46  public:
47    //Default Contructor
48    SVindex(); 
49
50    //
51    SVindex(const size_t);
52
53    // @return index_first
54    size_t index_first(void) const;
55
56    // @return index_second
57    size_t index_second(void) const;
58
59    // synch the object against alpha
60    void init(const utility::vector& alpha, const double);
61
62    // @return nof support vectors
63    size_t nof_sv(void) const;
64
65    // making first to an nsv. If already sv, nothing happens.
66    void nsv_first(void);
67
68    // making second to an nsv. If already sv, nothing happens.
69    void nsv_second(void);   
70
71    // randomizes the nsv part of vector and sets index_first to
72    // nof_sv_ (the first nsv)
73    void shuffle(void);
74
75    // @return nof samples
76    size_t size(void) const;
77
78    // making first to a sv. If already sv, nothing happens.
79    void sv_first(void);
80
81    // making second to a sv. If already sv, nothing happens.
82    void sv_second(void);
83
84    //
85    void update_first(const size_t);
86
87    //
88    void update_second(const size_t);
89
90    // @return value_first
91    size_t value_first(void) const;
92
93    // @return const ref value_second
94    size_t value_second(void) const;
95
96    size_t operator()(size_t i) const;
97
98  private:
99    size_t index_first_;
100    size_t index_second_;
101    size_t nof_sv_;
102    std::vector<size_t> vec_;
103    size_t value_first_; // vec_[index_first_] exists for fast access
104    size_t value_second_; // vec_[index_second_] exists for fast access
105   
106  };
107#endif /* DOXYGEN_SHOULD_SKIP_THIS */ 
108
109}}} // of namespace classifier, yat, and theplu
110
111#endif
Note: See TracBrowser for help on using the repository browser.