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

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

References #83. Changing project name to yat. Compilation will fail in this revision.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.0 KB
Line 
1#ifndef _theplu_classifier_sv_index_
2#define _theplu_classifier_sv_index_
3
4// $Id: SVindex.h 675 2006-10-10 12:08:45Z 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 "yat/utility/vector.h"
28
29#include <cassert>
30#include <vector>
31
32
33namespace theplu {
34namespace classifier { 
35
36#ifndef DOXYGEN_SHOULD_SKIP_THIS
37  /// @internal Class keeping track of which samples are support vectors and
38  /// not. The first nof_sv elements in the vector are indices of the
39  /// support vectors
40  ///
41  class SVindex
42  {
43
44  public:
45    //Default Contructor
46    SVindex(); 
47
48    //
49    SVindex(const size_t);
50
51    // @return index_first
52    inline size_t index_first(void) const 
53    { assert(index_first_<size()); return index_first_; }
54
55    // @return index_second
56    inline size_t index_second(void) const 
57    { assert(index_second_<size()); return index_second_; }
58
59    // synch the object against alpha
60    void init(const utility::vector& alpha, const double);
61
62    // @return nof samples
63    inline size_t size(void) const { return vec_.size(); }
64
65    // @return nof support vectors
66    inline size_t nof_sv(void) const { return nof_sv_; }
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    // 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    inline size_t value_first(void) const 
92    { assert(value_first_<size()); return value_first_; }
93
94    // @return const ref value_second
95    inline size_t value_second(void) const 
96    { assert(value_first_<size()); return value_second_; }
97
98    inline size_t operator()(size_t i) const { 
99      assert(i<size()); assert(vec_[i]<size()); return vec_[i]; }
100
101  private:
102    size_t index_first_;
103    size_t index_second_;
104    size_t nof_sv_;
105    std::vector<size_t> vec_;
106    size_t value_first_; // vec_[index_first_] exists for fast access
107    size_t value_second_; // vec_[index_second_] exists for fast access
108   
109  };
110#endif /* DOXYGEN_SHOULD_SKIP_THIS */ 
111
112}} // of namespace classifier and namespace theplu
113
114#endif
Note: See TracBrowser for help on using the repository browser.