Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
bae44f67
Commit
bae44f67
authored
Jun 03, 2011
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added a kmeans test
--HG-- rename : dlib/test/hash.cpp => dlib/test/kmeans.cpp
parent
29bd6bd1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
121 additions
and
0 deletions
+121
-0
CMakeLists.txt
dlib/test/CMakeLists.txt
+1
-0
kmeans.cpp
dlib/test/kmeans.cpp
+119
-0
makefile
dlib/test/makefile
+1
-0
No files found.
dlib/test/CMakeLists.txt
View file @
bae44f67
...
@@ -53,6 +53,7 @@ set (tests
...
@@ -53,6 +53,7 @@ set (tests
is_same_object.cpp
is_same_object.cpp
kcentroid.cpp
kcentroid.cpp
kernel_matrix.cpp
kernel_matrix.cpp
kmeans.cpp
least_squares.cpp
least_squares.cpp
linear_manifold_regularizer.cpp
linear_manifold_regularizer.cpp
lz77_buffer.cpp
lz77_buffer.cpp
...
...
dlib/test/kmeans.cpp
0 → 100644
View file @
bae44f67
// Copyright (C) 2011 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#include <sstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <dlib/svm.h>
#include <dlib/matrix.h>
#include "tester.h"
namespace
{
using
namespace
test
;
using
namespace
dlib
;
using
namespace
std
;
logger
dlog
(
"test.kmeans"
);
dlib
::
rand
rnd
;
template
<
typename
sample_type
>
void
run_test
(
const
std
::
vector
<
sample_type
>&
seed_centers
)
{
print_spinner
();
sample_type
samp
;
std
::
vector
<
sample_type
>
samples
;
for
(
unsigned
long
j
=
0
;
j
<
seed_centers
.
size
();
++
j
)
{
for
(
int
i
=
0
;
i
<
250
;
++
i
)
{
samp
=
randm
(
seed_centers
[
0
].
size
(),
1
,
rnd
)
-
0.5
;
samples
.
push_back
(
samp
+
seed_centers
[
j
]);
}
}
randomize_samples
(
samples
);
std
::
vector
<
sample_type
>
centers
;
pick_initial_centers
(
seed_centers
.
size
(),
centers
,
samples
,
linear_kernel
<
sample_type
>
());
DLIB_TEST
(
centers
.
size
()
==
seed_centers
.
size
());
std
::
vector
<
int
>
hits
(
centers
.
size
(),
0
);
for
(
unsigned
long
i
=
0
;
i
<
samples
.
size
();
++
i
)
{
unsigned
long
best_idx
=
0
;
double
best_dist
=
1e100
;
for
(
unsigned
long
j
=
0
;
j
<
centers
.
size
();
++
j
)
{
if
(
length
(
samples
[
i
]
-
centers
[
j
])
<
best_dist
)
{
best_dist
=
length
(
samples
[
i
]
-
centers
[
j
]);
best_idx
=
j
;
}
}
hits
[
best_idx
]
++
;
}
for
(
unsigned
long
i
=
0
;
i
<
hits
.
size
();
++
i
)
{
DLIB_TEST
(
hits
[
i
]
==
250
);
}
}
class
test_kmeans
:
public
tester
{
public
:
test_kmeans
(
)
:
tester
(
"test_kmeans"
,
"Runs tests on the find_clusters_using_kmeans() function."
)
{}
void
perform_test
(
)
{
{
dlog
<<
LINFO
<<
"test dlib::vector<double,2>"
;
typedef
dlib
::
vector
<
double
,
2
>
sample_type
;
std
::
vector
<
sample_type
>
seed_centers
;
seed_centers
.
push_back
(
sample_type
(
10
,
10
));
seed_centers
.
push_back
(
sample_type
(
10
,
-
10
));
seed_centers
.
push_back
(
sample_type
(
-
10
,
10
));
seed_centers
.
push_back
(
sample_type
(
-
10
,
-
10
));
run_test
(
seed_centers
);
}
{
dlog
<<
LINFO
<<
"test dlib::matrix<double,3,1>"
;
typedef
dlib
::
matrix
<
double
,
3
,
1
>
sample_type
;
std
::
vector
<
sample_type
>
seed_centers
;
sample_type
samp
;
samp
=
10
,
10
,
0
;
seed_centers
.
push_back
(
samp
);
samp
=
-
10
,
10
,
1
;
seed_centers
.
push_back
(
samp
);
samp
=
-
10
,
-
10
,
2
;
seed_centers
.
push_back
(
samp
);
run_test
(
seed_centers
);
}
}
}
a
;
}
dlib/test/makefile
View file @
bae44f67
...
@@ -63,6 +63,7 @@ SRC += image.cpp
...
@@ -63,6 +63,7 @@ SRC += image.cpp
SRC
+=
is_same_object.cpp
SRC
+=
is_same_object.cpp
SRC
+=
kcentroid.cpp
SRC
+=
kcentroid.cpp
SRC
+=
kernel_matrix.cpp
SRC
+=
kernel_matrix.cpp
SRC
+=
kmeans.cpp
SRC
+=
least_squares.cpp
SRC
+=
least_squares.cpp
SRC
+=
linear_manifold_regularizer.cpp
SRC
+=
linear_manifold_regularizer.cpp
SRC
+=
lz77_buffer.cpp
SRC
+=
lz77_buffer.cpp
...
...
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