1112 |
21 Feb 08 |
markus |
// $Id$ |
1112 |
21 Feb 08 |
markus |
2 |
|
1437 |
25 Aug 08 |
peter |
3 |
/* |
2119 |
12 Dec 09 |
peter |
Copyright (C) 2008 Jari Häkkinen, Peter Johansson, Markus Ringnér |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2012 Peter Johansson |
1437 |
25 Aug 08 |
peter |
6 |
|
1437 |
25 Aug 08 |
peter |
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 |
The yat library is free software; you can redistribute it and/or |
1437 |
25 Aug 08 |
peter |
modify it under the terms of the GNU General Public License as |
1486 |
09 Sep 08 |
jari |
published by the Free Software Foundation; either version 3 of the |
1437 |
25 Aug 08 |
peter |
License, or (at your option) any later version. |
1437 |
25 Aug 08 |
peter |
13 |
|
1437 |
25 Aug 08 |
peter |
The yat library is distributed in the hope that it will be useful, |
1437 |
25 Aug 08 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
1437 |
25 Aug 08 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1437 |
25 Aug 08 |
peter |
General Public License for more details. |
1437 |
25 Aug 08 |
peter |
18 |
|
1437 |
25 Aug 08 |
peter |
You should have received a copy of the GNU General Public License |
1487 |
10 Sep 08 |
jari |
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_ReciprocalRank.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_ReciprocalRank::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/(j+1); |
1112 |
21 Feb 08 |
markus |
46 |
} |
1112 |
21 Feb 08 |
markus |
47 |
|
1112 |
21 Feb 08 |
markus |
48 |
}}} |