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

Last change on this file since 865 was 865, checked in by Peter, 14 years ago

changing URL to http://trac.thep.lu.se/trac/yat

  • 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 865 2007-09-10 19:41:04Z peter $
5
6/*
7  Copyright (C) 2006 Jari Häkkinen, Peter Johansson
8  Copyright (C) 2007 Jari Häkkinen
9
10  This file is part of the yat library, http://trac.thep.lu.se/trac/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#ifndef DOXYGEN_SHOULD_SKIP_THIS
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    //
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    //
86    void update_first(const size_t);
87
88    //
89    void update_second(const size_t);
90
91    // @return value_first
92    size_t value_first(void) const;
93
94    // @return const ref value_second
95    size_t value_second(void) const;
96
97    size_t operator()(size_t i) const;
98
99  private:
100    size_t index_first_;
101    size_t index_second_;
102    size_t nof_sv_;
103    std::vector<size_t> vec_;
104    size_t value_first_; // vec_[index_first_] exists for fast access
105    size_t value_second_; // vec_[index_second_] exists for fast access
106   
107  };
108#endif /* DOXYGEN_SHOULD_SKIP_THIS */ 
109
110}}} // of namespace classifier, yat, and theplu
111
112#endif
Note: See TracBrowser for help on using the repository browser.