Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
34013251
Commit
34013251
authored
Mar 14, 2013
by
Davis King
Browse files
Added unit tests for the find_k_nearest_neighbors_lsh() method
and related tools.
parent
5cee2563
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
0 deletions
+60
-0
dlib/test/linear_manifold_regularizer.cpp
dlib/test/linear_manifold_regularizer.cpp
+60
-0
No files found.
dlib/test/linear_manifold_regularizer.cpp
View file @
34013251
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
#include <dlib/svm.h>
#include <dlib/svm.h>
#include <dlib/rand.h>
#include <dlib/rand.h>
#include <dlib/string.h>
#include <dlib/string.h>
#include <dlib/graph_utils_threaded.h>
#include <vector>
#include <vector>
#include <sstream>
#include <sstream>
#include <ctime>
#include <ctime>
...
@@ -17,6 +18,63 @@ namespace
...
@@ -17,6 +18,63 @@ namespace
using
namespace
std
;
using
namespace
std
;
dlib
::
logger
dlog
(
"test.linear_manifold_regularizer"
);
dlib
::
logger
dlog
(
"test.linear_manifold_regularizer"
);
template
<
typename
hash_type
,
typename
samples_type
>
void
test_find_k_nearest_neighbors_lsh
(
const
samples_type
&
samples
)
{
std
::
vector
<
sample_pair
>
edges1
,
edges2
;
find_k_nearest_neighbors
(
samples
,
cosine_distance
(),
2
,
edges1
);
find_k_nearest_neighbors_lsh
(
samples
,
cosine_distance
(),
hash_type
(),
2
,
6
,
edges2
,
2
);
std
::
sort
(
edges1
.
begin
(),
edges1
.
end
(),
order_by_index
<
sample_pair
>
);
std
::
sort
(
edges2
.
begin
(),
edges2
.
end
(),
order_by_index
<
sample_pair
>
);
DLIB_TEST_MSG
(
edges1
.
size
()
==
edges2
.
size
(),
edges1
.
size
()
<<
" "
<<
edges2
.
size
());
for
(
unsigned
long
i
=
0
;
i
<
edges1
.
size
();
++
i
)
{
DLIB_TEST
(
edges1
[
i
]
==
edges2
[
i
]);
DLIB_TEST
(
edges1
[
i
].
distance
()
==
edges2
[
i
].
distance
());
}
}
void
test_knn_lsh_sparse
()
{
dlib
::
rand
rnd
;
std
::
vector
<
std
::
map
<
unsigned
long
,
double
>
>
samples
;
samples
.
resize
(
20
);
for
(
unsigned
int
i
=
0
;
i
<
samples
.
size
();
++
i
)
{
samples
[
i
][
0
]
=
rnd
.
get_random_gaussian
();
samples
[
i
][
2
]
=
rnd
.
get_random_gaussian
();
}
test_find_k_nearest_neighbors_lsh
<
hash_similar_angles_64
>
(
samples
);
test_find_k_nearest_neighbors_lsh
<
hash_similar_angles_128
>
(
samples
);
test_find_k_nearest_neighbors_lsh
<
hash_similar_angles_256
>
(
samples
);
test_find_k_nearest_neighbors_lsh
<
hash_similar_angles_512
>
(
samples
);
}
void
test_knn_lsh_dense
()
{
dlib
::
rand
rnd
;
std
::
vector
<
matrix
<
double
,
0
,
1
>
>
samples
;
samples
.
resize
(
20
);
for
(
unsigned
int
i
=
0
;
i
<
samples
.
size
();
++
i
)
{
samples
[
i
].
set_size
(
2
);
samples
[
i
](
0
)
=
rnd
.
get_random_gaussian
();
samples
[
i
](
1
)
=
rnd
.
get_random_gaussian
();
}
test_find_k_nearest_neighbors_lsh
<
hash_similar_angles_64
>
(
samples
);
test_find_k_nearest_neighbors_lsh
<
hash_similar_angles_128
>
(
samples
);
test_find_k_nearest_neighbors_lsh
<
hash_similar_angles_256
>
(
samples
);
test_find_k_nearest_neighbors_lsh
<
hash_similar_angles_512
>
(
samples
);
}
class
linear_manifold_regularizer_tester
:
public
tester
class
linear_manifold_regularizer_tester
:
public
tester
{
{
...
@@ -327,6 +385,8 @@ namespace
...
@@ -327,6 +385,8 @@ namespace
}
}
test_knn1
();
test_knn1
();
test_knn2
();
test_knn2
();
test_knn_lsh_sparse
();
test_knn_lsh_dense
();
}
}
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment