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
6d656c61
"vscode:/vscode.git/clone" did not exist on "2c7e625a155612ce0835ffdf5f9da43525b84150"
Commit
6d656c61
authored
Mar 30, 2012
by
Davis King
Browse files
Added some unit tests for the oca object.
parent
fda8545b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
86 additions
and
0 deletions
+86
-0
dlib/test/CMakeLists.txt
dlib/test/CMakeLists.txt
+1
-0
dlib/test/makefile
dlib/test/makefile
+1
-0
dlib/test/oca.cpp
dlib/test/oca.cpp
+84
-0
No files found.
dlib/test/CMakeLists.txt
View file @
6d656c61
...
...
@@ -74,6 +74,7 @@ set (tests
metaprogramming.cpp
multithreaded_object.cpp
object_detector.cpp
oca.cpp
one_vs_all_trainer.cpp
one_vs_one_trainer.cpp
optimization.cpp
...
...
dlib/test/makefile
View file @
6d656c61
...
...
@@ -89,6 +89,7 @@ SRC += member_function_pointer.cpp
SRC
+=
metaprogramming.cpp
SRC
+=
multithreaded_object.cpp
SRC
+=
object_detector.cpp
SRC
+=
oca.cpp
SRC
+=
one_vs_all_trainer.cpp
SRC
+=
one_vs_one_trainer.cpp
SRC
+=
optimization.cpp
...
...
dlib/test/oca.cpp
0 → 100644
View file @
6d656c61
// Copyright (C) 2012 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#include <dlib/optimization.h>
#include <dlib/svm.h>
#include <sstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <vector>
#include "tester.h"
namespace
{
using
namespace
test
;
using
namespace
dlib
;
using
namespace
std
;
logger
dlog
(
"test.oca"
);
// ----------------------------------------------------------------------------------------
class
test_oca
:
public
tester
{
public:
test_oca
(
)
:
tester
(
"test_oca"
,
"Runs tests on the oca component."
)
{
}
void
perform_test
(
)
{
print_spinner
();
typedef
matrix
<
double
,
0
,
1
>
w_type
;
w_type
w
;
std
::
vector
<
w_type
>
x
;
w_type
temp
(
2
);
temp
=
-
1
,
1
;
x
.
push_back
(
temp
);
temp
=
1
,
-
1
;
x
.
push_back
(
temp
);
std
::
vector
<
double
>
y
;
y
.
push_back
(
+
1
);
y
.
push_back
(
-
1
);
w_type
true_w
(
3
);
oca
solver
;
// test the version without a non-negativity constraint on w.
solver
(
make_oca_problem_c_svm
<
w_type
>
(
2.0
,
3.0
,
vector_to_matrix
(
x
),
vector_to_matrix
(
y
),
false
,
1e-12
,
40
),
w
,
false
);
dlog
<<
LINFO
<<
w
;
true_w
=
-
0.5
,
0.5
,
0
;
dlog
<<
LINFO
<<
"error: "
<<
max
(
abs
(
w
-
true_w
));
DLIB_TEST
(
max
(
abs
(
w
-
true_w
))
<
1e-10
);
print_spinner
();
// test the version with a non-negativity constraint on w.
solver
(
make_oca_problem_c_svm
<
w_type
>
(
2.0
,
3.0
,
vector_to_matrix
(
x
),
vector_to_matrix
(
y
),
false
,
1e-12
,
40
),
w
,
true
);
dlog
<<
LINFO
<<
w
;
true_w
=
0
,
1
,
0
;
dlog
<<
LINFO
<<
"error: "
<<
max
(
abs
(
w
-
true_w
));
DLIB_TEST
(
max
(
abs
(
w
-
true_w
))
<
1e-10
);
}
}
a
;
}
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