Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Added covertree libshogun example
- Loading branch information
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Written (W) 2011 Sergey Lisitsyn | ||
* Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society | ||
*/ | ||
|
||
#include <shogun/base/init.h> | ||
#include <shogun/mathematics/Math.h> | ||
#include <shogun/lib/CoverTree.h> | ||
|
||
using namespace shogun; | ||
|
||
class TEST_COVERTREE_POINT | ||
{ | ||
public: | ||
|
||
TEST_COVERTREE_POINT(int32_t index, double value) | ||
{ | ||
point_index = index; | ||
point_value = value; | ||
} | ||
|
||
inline double distance(const TEST_COVERTREE_POINT& p) const | ||
{ | ||
return CMath::abs(p.point_value-point_value); | ||
} | ||
|
||
inline bool operator==(const TEST_COVERTREE_POINT& p) const | ||
{ | ||
return (p.point_index==point_index); | ||
} | ||
|
||
int point_index; | ||
double point_value; | ||
}; | ||
|
||
|
||
int main(int argc, char** argv) | ||
{ | ||
init_shogun(); | ||
|
||
int N = 100; | ||
CoverTree<TEST_COVERTREE_POINT> coverTree(N); | ||
for (int i=0; i<N; i++) | ||
coverTree.insert(TEST_COVERTREE_POINT(i,i*i)); | ||
std::vector<TEST_COVERTREE_POINT> neighbors = | ||
coverTree.kNearestNeighbors(TEST_COVERTREE_POINT(0,0.0),N-1); | ||
|
||
exit_shogun(); | ||
return 0; | ||
} |