yat/classifier/SVindex.h

Code
Comments
Other
Rev Date Author Line
4200 19 Aug 22 peter 1 #ifndef _theplu_yat_classifier_sv_index_
4200 19 Aug 22 peter 2 #define _theplu_yat_classifier_sv_index_
660 27 Sep 06 peter 3
660 27 Sep 06 peter 4 // $Id$
660 27 Sep 06 peter 5
675 10 Oct 06 jari 6 /*
2119 12 Dec 09 peter 7   Copyright (C) 2006, 2007, 2008 Jari Häkkinen, Peter Johansson
2986 18 Feb 13 peter 8   Copyright (C) 2013 Jari Häkkinen
660 27 Sep 06 peter 9
1437 25 Aug 08 peter 10   This file is part of the yat library, http://dev.thep.lu.se/yat
675 10 Oct 06 jari 11
675 10 Oct 06 jari 12   The yat library is free software; you can redistribute it and/or
675 10 Oct 06 jari 13   modify it under the terms of the GNU General Public License as
1486 09 Sep 08 jari 14   published by the Free Software Foundation; either version 3 of the
675 10 Oct 06 jari 15   License, or (at your option) any later version.
675 10 Oct 06 jari 16
675 10 Oct 06 jari 17   The yat library is distributed in the hope that it will be useful,
675 10 Oct 06 jari 18   but WITHOUT ANY WARRANTY; without even the implied warranty of
675 10 Oct 06 jari 19   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
675 10 Oct 06 jari 20   General Public License for more details.
675 10 Oct 06 jari 21
675 10 Oct 06 jari 22   You should have received a copy of the GNU General Public License
1487 10 Sep 08 jari 23   along with yat. If not, see <http://www.gnu.org/licenses/>.
675 10 Oct 06 jari 24 */
675 10 Oct 06 jari 25
2966 23 Jan 13 jari 26 #include <cstddef>
660 27 Sep 06 peter 27 #include <vector>
660 27 Sep 06 peter 28
660 27 Sep 06 peter 29 namespace theplu {
680 11 Oct 06 jari 30 namespace yat {
757 19 Feb 07 jari 31
757 19 Feb 07 jari 32 namespace utility {
1120 21 Feb 08 peter 33   class Vector;
757 19 Feb 07 jari 34 }
757 19 Feb 07 jari 35
4200 19 Aug 22 peter 36 namespace classifier {
660 27 Sep 06 peter 37
966 11 Oct 07 peter 38   ///
1150 25 Feb 08 peter 39   /// \internal
1150 25 Feb 08 peter 40   ///
966 11 Oct 07 peter 41   /// Internal Class keeping track of which samples are support vectors and
660 27 Sep 06 peter 42   /// not. The first nof_sv elements in the vector are indices of the
660 27 Sep 06 peter 43   /// support vectors
660 27 Sep 06 peter 44   ///
660 27 Sep 06 peter 45   class SVindex
660 27 Sep 06 peter 46   {
660 27 Sep 06 peter 47
660 27 Sep 06 peter 48   public:
966 11 Oct 07 peter 49     ///Default Contructor
4200 19 Aug 22 peter 50     SVindex();
660 27 Sep 06 peter 51
4200 19 Aug 22 peter 52     /// Constructor
660 27 Sep 06 peter 53     SVindex(const size_t);
660 27 Sep 06 peter 54
966 11 Oct 07 peter 55     /// @return index_first
714 22 Dec 06 jari 56     size_t index_first(void) const;
660 27 Sep 06 peter 57
966 11 Oct 07 peter 58     /// @return index_second
714 22 Dec 06 jari 59     size_t index_second(void) const;
660 27 Sep 06 peter 60
966 11 Oct 07 peter 61     /// synch the object against alpha
1120 21 Feb 08 peter 62     void init(const utility::Vector& alpha, const double);
660 27 Sep 06 peter 63
966 11 Oct 07 peter 64     /// @return nof support vectors
714 22 Dec 06 jari 65     size_t nof_sv(void) const;
660 27 Sep 06 peter 66
966 11 Oct 07 peter 67     /// making first to an nsv. If already sv, nothing happens.
660 27 Sep 06 peter 68     void nsv_first(void);
660 27 Sep 06 peter 69
966 11 Oct 07 peter 70     /// making second to an nsv. If already sv, nothing happens.
4200 19 Aug 22 peter 71     void nsv_second(void);
660 27 Sep 06 peter 72
966 11 Oct 07 peter 73     /// randomizes the nsv part of vector and sets index_first to
966 11 Oct 07 peter 74     /// nof_sv_ (the first nsv)
660 27 Sep 06 peter 75     void shuffle(void);
660 27 Sep 06 peter 76
966 11 Oct 07 peter 77     /// @return nof samples
714 22 Dec 06 jari 78     size_t size(void) const;
714 22 Dec 06 jari 79
966 11 Oct 07 peter 80     /// making first to a sv. If already sv, nothing happens.
660 27 Sep 06 peter 81     void sv_first(void);
660 27 Sep 06 peter 82
966 11 Oct 07 peter 83     /// making second to a sv. If already sv, nothing happens.
660 27 Sep 06 peter 84     void sv_second(void);
660 27 Sep 06 peter 85
966 11 Oct 07 peter 86     /// set index_first to \a i
966 11 Oct 07 peter 87     void update_first(const size_t i);
660 27 Sep 06 peter 88
966 11 Oct 07 peter 89     /// set index_second to \a i
966 11 Oct 07 peter 90     void update_second(const size_t i);
660 27 Sep 06 peter 91
966 11 Oct 07 peter 92     /// @return value_first
714 22 Dec 06 jari 93     size_t value_first(void) const;
660 27 Sep 06 peter 94
966 11 Oct 07 peter 95     /// @return value_second
714 22 Dec 06 jari 96     size_t value_second(void) const;
660 27 Sep 06 peter 97
966 11 Oct 07 peter 98     /// \return index \a i (if i<nof_sv() index is sv)
714 22 Dec 06 jari 99     size_t operator()(size_t i) const;
660 27 Sep 06 peter 100
660 27 Sep 06 peter 101   private:
660 27 Sep 06 peter 102     size_t index_first_;
660 27 Sep 06 peter 103     size_t index_second_;
660 27 Sep 06 peter 104     size_t nof_sv_;
660 27 Sep 06 peter 105     std::vector<size_t> vec_;
660 27 Sep 06 peter 106     size_t value_first_; // vec_[index_first_] exists for fast access
660 27 Sep 06 peter 107     size_t value_second_; // vec_[index_second_] exists for fast access
4200 19 Aug 22 peter 108
660 27 Sep 06 peter 109   };
660 27 Sep 06 peter 110
680 11 Oct 06 jari 111 }}} // of namespace classifier, yat, and theplu
660 27 Sep 06 peter 112
660 27 Sep 06 peter 113 #endif