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