# source:tags/0.4/doc/concepts.doxygen@1481

Last change on this file since 1481 was 1275, checked in by Jari Häkkinen, 14 years ago

• Property svn:eol-style set to native
• Property svn:keywords set to Id
File size: 4.1 KB
Line
1// $Id: concepts.doxygen 1275 2008-04-11 06:10:12Z jari$
2//
3// Copyright (C) 2008 Peter Johansson, Markus Ringnér
4//
5// This file is part of the yat library, http://trac.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 2 of the
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 this program; if not, write to the Free Software
19// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20// 02111-1307, USA.
21
22
23/**
24\page Concepts Concepts
25
27
28- \subpage concept_distance
29- \subpage concept_neighbor_weighting
30*/
31
32
33/**
34\page concept_distance Distance
35
36\section Description
37
38\ref concept_distance is a concept for classes implementing different
39alternatives to calculate the distance between two points.
40
41\section Requirements
42
43Classes modelling the concept \ref concept_distance should implement
44the following public function:
45
46\verbatim
47template<typename Iter1, typename Iter2>
48double  operator() (Iter1 beg1, Iter1 end1, Iter2 beg2) const
49\endverbatim
50
51This function should calculate and return the distance between
52elements of two ranges. The first range is given by [\a beg1, \a end1)
53and the second range starts with \a beg2 and has the same length as
54the first range. The function should support iterators of the category
55std::forward_iterator. The function should provide both a fast
56calculation for unweighted iterators and a calculation for weighted
57iterators. The latter correspond to the case where elements in a range
58have both a value and a weight. The selection between unweighted and
59weighted implementations should utilize
60theplu::yat::utility::unweighted_iterator_tag and
61theplu::yat::utility::weighted_iterator_tag. Moreover
62theplu::yat::utility::weighted_if_any2 should be utilized to provide a
63weighted implementation if any of the two ranges is weighted, and an
64unweighted implementation when both ranges are unweighted.
65
66\section Implementations
67
68Examples of classes modelling the concept \ref concept_distance
69include theplu::yat::statistics::PearsonDistance and
70theplu::yat::statistics::EuclideanDistance.
71
72\see \ref weighted_distance
73
74*/
75
76/**
77\page concept_neighbor_weighting Neighbor Weighting Method
78
79\section Description
80
81\ref concept_neighbor_weighting is a concept used in connection with
82theplu::yat::classifier::KNN - classes used as the template argument
83NeighborWeighting should implement this concept.
84
85\section Requirements
86
87Classes modelling the concept \ref concept_neighbor_weighting should
88implement the following public function:
89
90\verbatim
91void operator()(const utility::VectorBase& distance, const std::vector<size_t> k_sorted,
92                const Target& target, utility::VectorMutable& prediction) const
93\endverbatim
94
95For 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
97distance contains the distances from a test sample to all training
98samples. The vector \a k_sorted contains the indices (for both \a
99distance and \a target) to the k training samples with the smallest
100distances to the test sample. The class for each training sample is
101given by \a target, which is sorted in the same sample order as \a
102distance. For each class the function calculates a total vote based on
103the the nearest neighbors of the test sample that belong to the
104class. The total vote for each class is stored in the vector \a
105prediction.  The function should be implemented such that nearest
106neighbors with distance infinity do not vote.
107
108\section Implementations
109
110Examples of classes modelling the concept \ref
111concept_neighbor_weighting include
112theplu::yat::classifier::KNN_Uniform,
113theplu::yat::classifier::KNN_ReciprocalDistance and
114theplu::yat::classifier::KNN_ReciprocalRank.
115
116*/
Note: See TracBrowser for help on using the repository browser.