source: trunk/c++_tools/classifier/SVindex.h @ 660

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

closes #140 moved Index class to its own file and changed name to SVindex

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.2 KB
Line 
1#ifndef _theplu_classifier_sv_index_
2#define _theplu_classifier_sv_index_
3
4// $Id: SVindex.h 660 2006-09-27 08:53:56Z peter $
5
6#include <c++_tools/utility/vector.h>
7
8#include <cassert>
9#include <vector>
10
11
12namespace theplu {
13namespace classifier { 
14
15#ifndef DOXYGEN_SHOULD_SKIP_THIS
16  /// @internal Class keeping track of which samples are support vectors and
17  /// not. The first nof_sv elements in the vector are indices of the
18  /// support vectors
19  ///
20  class SVindex
21  {
22
23  public:
24    //Default Contructor
25    SVindex(); 
26
27    //
28    SVindex(const size_t);
29
30    // @return index_first
31    inline size_t index_first(void) const 
32    { assert(index_first_<size()); return index_first_; }
33
34    // @return index_second
35    inline size_t index_second(void) const 
36    { assert(index_second_<size()); return index_second_; }
37
38    // synch the object against alpha
39    void init(const utility::vector& alpha, const double);
40
41    // @return nof samples
42    inline size_t size(void) const { return vec_.size(); }
43
44    // @return nof support vectors
45    inline size_t nof_sv(void) const { return nof_sv_; }
46
47    // making first to an nsv. If already sv, nothing happens.
48    void nsv_first(void);
49
50    // making second to an nsv. If already sv, nothing happens.
51    void nsv_second(void);   
52
53    // randomizes the nsv part of vector and sets index_first to
54    // nof_sv_ (the first nsv)
55    void shuffle(void);
56
57    // making first to a sv. If already sv, nothing happens.
58    void sv_first(void);
59
60    // making second to a sv. If already sv, nothing happens.
61    void sv_second(void);
62
63    //
64    void update_first(const size_t);
65
66    //
67    void update_second(const size_t);
68
69    // @return value_first
70    inline size_t value_first(void) const 
71    { assert(value_first_<size()); return value_first_; }
72
73    // @return const ref value_second
74    inline size_t value_second(void) const 
75    { assert(value_first_<size()); return value_second_; }
76
77    inline size_t operator()(size_t i) const { 
78      assert(i<size()); assert(vec_[i]<size()); return vec_[i]; }
79
80  private:
81    size_t index_first_;
82    size_t index_second_;
83    size_t nof_sv_;
84    std::vector<size_t> vec_;
85    size_t value_first_; // vec_[index_first_] exists for fast access
86    size_t value_second_; // vec_[index_second_] exists for fast access
87   
88  };
89#endif /* DOXYGEN_SHOULD_SKIP_THIS */ 
90
91}} // of namespace classifier and namespace theplu
92
93#endif
Note: See TracBrowser for help on using the repository browser.