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

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

Addresses #436. GPL license copy reference should also be updated.

  • 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 1487 2008-09-10 08:41:36Z jari $
5
6/*
7  Copyright (C) 2006, 2007 Jari Häkkinen, Peter Johansson
8  Copyright (C) 2008 Peter Johansson
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 <vector>
27
28namespace theplu {
29namespace yat {
30
31namespace utility {
32  class Vector;
33}
34
35namespace classifier { 
36
37  ///
38  /// \internal
39  ///
40  /// Internal Class keeping track of which samples are support vectors and
41  /// not. The first nof_sv elements in the vector are indices of the
42  /// support vectors
43  ///
44  class SVindex
45  {
46
47  public:
48    ///Default Contructor
49    SVindex(); 
50
51    /// Constructor
52    SVindex(const size_t);
53
54    /// @return index_first
55    size_t index_first(void) const;
56
57    /// @return index_second
58    size_t index_second(void) const;
59
60    /// synch the object against alpha
61    void init(const utility::Vector& alpha, const double);
62
63    /// @return nof support vectors
64    size_t nof_sv(void) const;
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    /// @return nof samples
77    size_t size(void) const;
78
79    /// making first to a sv. If already sv, nothing happens.
80    void sv_first(void);
81
82    /// making second to a sv. If already sv, nothing happens.
83    void sv_second(void);
84
85    /// set index_first to \a i
86    void update_first(const size_t i);
87
88    /// set index_second to \a i
89    void update_second(const size_t i);
90
91    /// @return value_first
92    size_t value_first(void) const;
93
94    /// @return value_second
95    size_t value_second(void) const;
96
97    /// \return index \a i (if i<nof_sv() index is sv)
98    size_t operator()(size_t i) const;
99
100  private:
101    size_t index_first_;
102    size_t index_second_;
103    size_t nof_sv_;
104    std::vector<size_t> vec_;
105    size_t value_first_; // vec_[index_first_] exists for fast access
106    size_t value_second_; // vec_[index_second_] exists for fast access
107   
108  };
109
110}}} // of namespace classifier, yat, and theplu
111
112#endif
Note: See TracBrowser for help on using the repository browser.