source: trunk/yat/classifier/SVindex.h

Last change on this file was 4207, checked in by Peter, 6 weeks ago

update copyright statements

  • 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 4207 2022-08-26 04:36:28Z peter $
5
6/*
7  Copyright (C) 2006, 2007, 2008 Jari Häkkinen, Peter Johansson
8  Copyright (C) 2013 Jari Häkkinen
9  Copyright (C) 2022 Peter Johansson
10
11  This file is part of the yat library, http://dev.thep.lu.se/yat
12
13  The yat library is free software; you can redistribute it and/or
14  modify it under the terms of the GNU General Public License as
15  published by the Free Software Foundation; either version 3 of the
16  License, or (at your option) any later version.
17
18  The yat library is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  General Public License for more details.
22
23  You should have received a copy of the GNU General Public License
24  along with yat. If not, see <http://www.gnu.org/licenses/>.
25*/
26
27#include <cstddef>
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.