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 |
// $Id$ |
660 |
27 Sep 06 |
peter |
5 |
|
675 |
10 Oct 06 |
jari |
6 |
/* |
2119 |
12 Dec 09 |
peter |
Copyright (C) 2006, 2007, 2008 Jari Häkkinen, Peter Johansson |
2986 |
18 Feb 13 |
peter |
Copyright (C) 2013 Jari Häkkinen |
660 |
27 Sep 06 |
peter |
9 |
|
1437 |
25 Aug 08 |
peter |
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 |
The yat library is free software; you can redistribute it and/or |
675 |
10 Oct 06 |
jari |
modify it under the terms of the GNU General Public License as |
1486 |
09 Sep 08 |
jari |
published by the Free Software Foundation; either version 3 of the |
675 |
10 Oct 06 |
jari |
License, or (at your option) any later version. |
675 |
10 Oct 06 |
jari |
16 |
|
675 |
10 Oct 06 |
jari |
The yat library is distributed in the hope that it will be useful, |
675 |
10 Oct 06 |
jari |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
675 |
10 Oct 06 |
jari |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
675 |
10 Oct 06 |
jari |
General Public License for more details. |
675 |
10 Oct 06 |
jari |
21 |
|
675 |
10 Oct 06 |
jari |
You should have received a copy of the GNU General Public License |
1487 |
10 Sep 08 |
jari |
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 |
/// \internal |
1150 |
25 Feb 08 |
peter |
40 |
/// |
966 |
11 Oct 07 |
peter |
/// Internal Class keeping track of which samples are support vectors and |
660 |
27 Sep 06 |
peter |
/// not. The first nof_sv elements in the vector are indices of the |
660 |
27 Sep 06 |
peter |
/// 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 |
///Default Contructor |
4200 |
19 Aug 22 |
peter |
50 |
SVindex(); |
660 |
27 Sep 06 |
peter |
51 |
|
4200 |
19 Aug 22 |
peter |
/// Constructor |
660 |
27 Sep 06 |
peter |
53 |
SVindex(const size_t); |
660 |
27 Sep 06 |
peter |
54 |
|
966 |
11 Oct 07 |
peter |
/// @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 |
/// @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 |
/// 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 |
/// @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 |
/// 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 |
/// 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 |
/// randomizes the nsv part of vector and sets index_first to |
966 |
11 Oct 07 |
peter |
/// 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 |
/// @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 |
/// 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 |
/// 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 |
/// 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 |
/// 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 |
/// @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 |
/// @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 |
/// \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 |