source: trunk/yat/classifier/KNN_ReciprocalRank.h

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

update copyright statements

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.8 KB
Line 
1#ifndef theplu_yat_classifier_knn_reciprocal_rank_h
2#define theplu_yat_classifier_knn_reciprocal_rank_h
3
4// $Id: KNN_ReciprocalRank.h 4207 2022-08-26 04:36:28Z peter $
5
6/*
7  Copyright (C) 2008 Jari Häkkinen, Peter Johansson, Markus Ringnér
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
33  namespace utility {
34    class VectorBase;
35    class VectorMutable;
36  }
37
38namespace classifier {
39
40  class Target;
41
42
43  ///
44  /// @brief A model of the concept \ref concept_neighbor_weighting to
45  /// be used with KNN to weight the votes of the k nearest neighbors
46  /// of a sample.
47  ///
48  /// KNN_ReciprocalRank weights the vote of a nearest neighbor with
49  /// its reciprocal rank. The class of the nearest neighbor gets
50  /// the vote 1/1, the class of the second nearest neighbor gets the
51  /// vote 1/2, and so on
52  ///
53  struct KNN_ReciprocalRank
54  {
55    /**
56       The total vote for each class is calculated and returned in prediction.
57    */
58    void operator()(const utility::VectorBase& distance,
59                    const std::vector<size_t>& k_sorted,
60                    const Target& target,
61                    utility::VectorMutable& prediction) const;
62  };
63
64}}} // of namespace classifier, yat, and theplu
65
66#endif
Note: See TracBrowser for help on using the repository browser.