1 | // $Id: concepts.doxygen 1522 2008-09-23 13:41:19Z peter $ |
---|
2 | // |
---|
3 | // Copyright (C) 2008 Peter Johansson, Markus Ringnér |
---|
4 | // |
---|
5 | // This file is part of the yat library, http://dev.thep.lu.se/yat |
---|
6 | // |
---|
7 | // The yat library is free software; you can redistribute it and/or |
---|
8 | // modify it under the terms of the GNU General Public License as |
---|
9 | // published by the Free Software Foundation; either version 3 of the |
---|
10 | // License, or (at your option) any later version. |
---|
11 | // |
---|
12 | // The yat library is distributed in the hope that it will be useful, |
---|
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
15 | // General Public License for more details. |
---|
16 | // |
---|
17 | // You should have received a copy of the GNU General Public License |
---|
18 | // along with yat. If not, see <http://www.gnu.org/licenses/>. |
---|
19 | |
---|
20 | |
---|
21 | /** |
---|
22 | \page Concepts Concepts |
---|
23 | |
---|
24 | This page lists all the C++ concepts in the yat project. |
---|
25 | |
---|
26 | - \subpage concept_distance |
---|
27 | - \subpage concept_neighbor_weighting |
---|
28 | */ |
---|
29 | |
---|
30 | |
---|
31 | /** |
---|
32 | \page concept_distance Distance |
---|
33 | |
---|
34 | \section Description |
---|
35 | |
---|
36 | \ref concept_distance is a concept for classes implementing different |
---|
37 | alternatives to calculate the distance between two points. |
---|
38 | |
---|
39 | \section Requirements |
---|
40 | |
---|
41 | Classes modelling the concept \ref concept_distance should implement |
---|
42 | the following public function: |
---|
43 | |
---|
44 | \verbatim |
---|
45 | template<typename Iter1, typename Iter2> |
---|
46 | double operator() (Iter1 beg1, Iter1 end1, Iter2 beg2) const |
---|
47 | \endverbatim |
---|
48 | |
---|
49 | This function should calculate and return the distance between |
---|
50 | elements of two ranges. The first range is given by [\a beg1, \a end1) |
---|
51 | and the second range starts with \a beg2 and has the same length as |
---|
52 | the first range. The function should support iterators of the category |
---|
53 | std::forward_iterator. The function should provide both a fast |
---|
54 | calculation for unweighted iterators and a calculation for weighted |
---|
55 | iterators. The latter correspond to the case where elements in a range |
---|
56 | have both a value and a weight. The selection between unweighted and |
---|
57 | weighted implementations should utilize |
---|
58 | theplu::yat::utility::unweighted_iterator_tag and |
---|
59 | theplu::yat::utility::weighted_iterator_tag. Moreover |
---|
60 | theplu::yat::utility::weighted_if_any2 should be utilized to provide a |
---|
61 | weighted implementation if any of the two ranges is weighted, and an |
---|
62 | unweighted implementation when both ranges are unweighted. |
---|
63 | |
---|
64 | \section Implementations |
---|
65 | |
---|
66 | Examples of classes modelling the concept \ref concept_distance |
---|
67 | include theplu::yat::statistics::PearsonDistance and |
---|
68 | theplu::yat::statistics::EuclideanDistance. |
---|
69 | |
---|
70 | \see \ref weighted_distance |
---|
71 | |
---|
72 | */ |
---|
73 | |
---|
74 | /** |
---|
75 | \page concept_neighbor_weighting Neighbor Weighting Method |
---|
76 | |
---|
77 | \section Description |
---|
78 | |
---|
79 | \ref concept_neighbor_weighting is a concept used in connection with |
---|
80 | theplu::yat::classifier::KNN - classes used as the template argument |
---|
81 | NeighborWeighting should implement this concept. |
---|
82 | |
---|
83 | \section Requirements |
---|
84 | |
---|
85 | Classes modelling the concept \ref concept_neighbor_weighting should |
---|
86 | implement the following public function: |
---|
87 | |
---|
88 | \verbatim |
---|
89 | void operator()(const utility::VectorBase& distance, |
---|
90 | const std::vector<size_t>& k_sorted, |
---|
91 | const Target& target, |
---|
92 | utility::VectorMutable& prediction) const |
---|
93 | \endverbatim |
---|
94 | |
---|
95 | For a test sample, this function should calculate a total vote |
---|
96 | (i.e. based on all k nearest neighbors) for each class. The vector \a |
---|
97 | distance contains the distances from a test sample to all training |
---|
98 | samples. The vector \a k_sorted contains the indices (for both \a |
---|
99 | distance and \a target) to the k training samples with the smallest |
---|
100 | distances to the test sample. The class for each training sample is |
---|
101 | given by \a target, which is sorted in the same sample order as \a |
---|
102 | distance. For each class the function calculates a total vote based on |
---|
103 | the the nearest neighbors of the test sample that belong to the |
---|
104 | class. The total vote for each class is stored in the vector \a |
---|
105 | prediction. The function should be implemented such that nearest |
---|
106 | neighbors with distance infinity do not vote. |
---|
107 | |
---|
108 | \section Implementations |
---|
109 | |
---|
110 | Examples of classes modelling the concept \ref |
---|
111 | concept_neighbor_weighting include |
---|
112 | theplu::yat::classifier::KNN_Uniform, |
---|
113 | theplu::yat::classifier::KNN_ReciprocalDistance and |
---|
114 | theplu::yat::classifier::KNN_ReciprocalRank. |
---|
115 | |
---|
116 | */ |
---|