yat/classifier/KNN_ReciprocalDistance.cc

Code
Comments
Other
Rev Date Author Line
1112 21 Feb 08 markus 1 // $Id$
1112 21 Feb 08 markus 2
1437 25 Aug 08 peter 3 // $Id$
1437 25 Aug 08 peter 4
1437 25 Aug 08 peter 5 /*
2119 12 Dec 09 peter 6   Copyright (C) 2008 Jari Häkkinen, Peter Johansson, Markus Ringnér
4359 23 Aug 23 peter 7   Copyright (C) 2012 Peter Johansson
1437 25 Aug 08 peter 8
1437 25 Aug 08 peter 9   This file is part of the yat library, http://dev.thep.lu.se/yat
1437 25 Aug 08 peter 10
1437 25 Aug 08 peter 11   The yat library is free software; you can redistribute it and/or
1437 25 Aug 08 peter 12   modify it under the terms of the GNU General Public License as
1486 09 Sep 08 jari 13   published by the Free Software Foundation; either version 3 of the
1437 25 Aug 08 peter 14   License, or (at your option) any later version.
1437 25 Aug 08 peter 15
1437 25 Aug 08 peter 16   The yat library is distributed in the hope that it will be useful,
1437 25 Aug 08 peter 17   but WITHOUT ANY WARRANTY; without even the implied warranty of
1437 25 Aug 08 peter 18   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1437 25 Aug 08 peter 19   General Public License for more details.
1437 25 Aug 08 peter 20
1437 25 Aug 08 peter 21   You should have received a copy of the GNU General Public License
1487 10 Sep 08 jari 22   along with yat. If not, see <http://www.gnu.org/licenses/>.
1437 25 Aug 08 peter 23 */
1437 25 Aug 08 peter 24
2881 18 Nov 12 peter 25 #include <config.h>
2881 18 Nov 12 peter 26
1112 21 Feb 08 markus 27 #include "KNN_ReciprocalDistance.h"
1112 21 Feb 08 markus 28 #include "Target.h"
1112 21 Feb 08 markus 29
1112 21 Feb 08 markus 30 #include "yat/utility/VectorBase.h"
1112 21 Feb 08 markus 31 #include "yat/utility/VectorMutable.h"
1112 21 Feb 08 markus 32
1112 21 Feb 08 markus 33 #include <vector>
1112 21 Feb 08 markus 34
1112 21 Feb 08 markus 35 namespace theplu {
1112 21 Feb 08 markus 36 namespace yat {
1112 21 Feb 08 markus 37 namespace classifier {
1112 21 Feb 08 markus 38
1112 21 Feb 08 markus 39   void KNN_ReciprocalDistance::operator()(const utility::VectorBase& distance,
4200 19 Aug 22 peter 40                                           const std::vector<size_t>& k_sorted,
4200 19 Aug 22 peter 41                                           const Target& target,
1112 21 Feb 08 markus 42                                           utility::VectorMutable& prediction) const
1112 21 Feb 08 markus 43   {
4200 19 Aug 22 peter 44     for(size_t j=0;j<k_sorted.size();j++)
4200 19 Aug 22 peter 45       prediction(target(k_sorted[j]))+=1.0/distance(k_sorted[j]);
1112 21 Feb 08 markus 46   }
1112 21 Feb 08 markus 47
1112 21 Feb 08 markus 48 }}}