source: branches/0.4-stable/yat/classifier/SVindex.h @ 1392

Last change on this file since 1392 was 1392, checked in by Peter, 15 years ago

trac has moved

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.8 KB
Line 
1#ifndef _theplu_yat_classifier_sv_index_
2#define _theplu_yat_classifier_sv_index_
3
4// $Id: SVindex.h 1392 2008-07-28 19:35:30Z peter $
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 2 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 this program; if not, write to the Free Software
24  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25  02111-1307, USA.
26*/
27
28#include <vector>
29
30namespace theplu {
31namespace yat {
32
33namespace utility {
34  class Vector;
35}
36
37namespace classifier { 
38
39  ///
40  /// \internal
41  ///
42  /// Internal Class keeping track of which samples are support vectors and
43  /// not. The first nof_sv elements in the vector are indices of the
44  /// support vectors
45  ///
46  class SVindex
47  {
48
49  public:
50    ///Default Contructor
51    SVindex(); 
52
53    /// Constructor
54    SVindex(const size_t);
55
56    /// @return index_first
57    size_t index_first(void) const;
58
59    /// @return index_second
60    size_t index_second(void) const;
61
62    /// synch the object against alpha
63    void init(const utility::Vector& alpha, const double);
64
65    /// @return nof support vectors
66    size_t nof_sv(void) const;
67
68    /// making first to an nsv. If already sv, nothing happens.
69    void nsv_first(void);
70
71    /// making second to an nsv. If already sv, nothing happens.
72    void nsv_second(void);   
73
74    /// randomizes the nsv part of vector and sets index_first to
75    /// nof_sv_ (the first nsv)
76    void shuffle(void);
77
78    /// @return nof samples
79    size_t size(void) const;
80
81    /// making first to a sv. If already sv, nothing happens.
82    void sv_first(void);
83
84    /// making second to a sv. If already sv, nothing happens.
85    void sv_second(void);
86
87    /// set index_first to \a i
88    void update_first(const size_t i);
89
90    /// set index_second to \a i
91    void update_second(const size_t i);
92
93    /// @return value_first
94    size_t value_first(void) const;
95
96    /// @return value_second
97    size_t value_second(void) const;
98
99    /// \return index \a i (if i<nof_sv() index is sv)
100    size_t operator()(size_t i) const;
101
102  private:
103    size_t index_first_;
104    size_t index_second_;
105    size_t nof_sv_;
106    std::vector<size_t> vec_;
107    size_t value_first_; // vec_[index_first_] exists for fast access
108    size_t value_second_; // vec_[index_second_] exists for fast access
109   
110  };
111
112}}} // of namespace classifier, yat, and theplu
113
114#endif
Note: See TracBrowser for help on using the repository browser.