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
ba33b82e
Commit
ba33b82e
authored
May 19, 2012
by
Davis King
Browse files
Added some tests to make sure the recent addition to svm_c_linear_trainer
works right.
parent
b7d81290
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
0 deletions
+59
-0
dlib/test/oca.cpp
dlib/test/oca.cpp
+59
-0
No files found.
dlib/test/oca.cpp
View file @
ba33b82e
...
@@ -43,6 +43,12 @@ namespace
...
@@ -43,6 +43,12 @@ namespace
typedef
matrix
<
double
,
0
,
1
>
w_type
;
typedef
matrix
<
double
,
0
,
1
>
w_type
;
w_type
w
;
w_type
w
;
decision_function
<
linear_kernel
<
w_type
>
>
df
;
svm_c_linear_trainer
<
linear_kernel
<
w_type
>
>
trainer
;
trainer
.
set_c_class1
(
2
);
trainer
.
set_c_class1
(
3
);
trainer
.
set_learns_nonnegative_weights
(
true
);
trainer
.
set_epsilon
(
1e-12
);
std
::
vector
<
w_type
>
x
;
std
::
vector
<
w_type
>
x
;
w_type
temp
(
2
);
w_type
temp
(
2
);
...
@@ -75,6 +81,13 @@ namespace
...
@@ -75,6 +81,13 @@ namespace
dlog
<<
LINFO
<<
"error: "
<<
max
(
abs
(
w
-
true_w
));
dlog
<<
LINFO
<<
"error: "
<<
max
(
abs
(
w
-
true_w
));
DLIB_TEST
(
max
(
abs
(
w
-
true_w
))
<
1e-10
);
DLIB_TEST
(
max
(
abs
(
w
-
true_w
))
<
1e-10
);
df
=
trainer
.
train
(
x
,
y
);
w
=
join_cols
(
df
.
basis_vectors
(
0
),
uniform_matrix
<
double
>
(
1
,
1
,
-
df
.
b
));
true_w
=
0
,
1
,
0
;
dlog
<<
LINFO
<<
"error: "
<<
max
(
abs
(
w
-
true_w
));
DLIB_TEST
(
max
(
abs
(
w
-
true_w
))
<
1e-10
);
print_spinner
();
print_spinner
();
// test the version with a non-negativity constraint on w.
// test the version with a non-negativity constraint on w.
...
@@ -132,6 +145,52 @@ namespace
...
@@ -132,6 +145,52 @@ namespace
true_w
=
1
,
0
,
0
;
true_w
=
1
,
0
,
0
;
dlog
<<
LINFO
<<
"error: "
<<
max
(
abs
(
w
-
true_w
));
dlog
<<
LINFO
<<
"error: "
<<
max
(
abs
(
w
-
true_w
));
DLIB_TEST
(
max
(
abs
(
w
-
true_w
))
<
1e-10
);
DLIB_TEST
(
max
(
abs
(
w
-
true_w
))
<
1e-10
);
df
=
trainer
.
train
(
x
,
y
);
w
=
join_cols
(
df
.
basis_vectors
(
0
),
uniform_matrix
<
double
>
(
1
,
1
,
-
df
.
b
));
true_w
=
1
,
0
,
0
;
dlog
<<
LINFO
<<
"error: "
<<
max
(
abs
(
w
-
true_w
));
DLIB_TEST
(
max
(
abs
(
w
-
true_w
))
<
1e-10
);
x
.
clear
();
y
.
clear
();
temp
=
-
2
,
2
;
x
.
push_back
(
temp
);
temp
=
0
,
-
0
;
x
.
push_back
(
temp
);
y
.
push_back
(
+
1
);
y
.
push_back
(
-
1
);
trainer
.
set_c
(
10
);
df
=
trainer
.
train
(
x
,
y
);
w
=
join_cols
(
df
.
basis_vectors
(
0
),
uniform_matrix
<
double
>
(
1
,
1
,
-
df
.
b
));
true_w
=
0
,
1
,
-
1
;
dlog
<<
LINFO
<<
"w: "
<<
trans
(
w
);
dlog
<<
LINFO
<<
"error: "
<<
max
(
abs
(
w
-
true_w
));
DLIB_TEST
(
max
(
abs
(
w
-
true_w
))
<
1e-10
);
x
.
clear
();
y
.
clear
();
temp
=
-
2
,
2
;
x
.
push_back
(
temp
);
temp
=
0
,
-
0
;
x
.
push_back
(
temp
);
y
.
push_back
(
-
1
);
y
.
push_back
(
+
1
);
trainer
.
set_c
(
10
);
df
=
trainer
.
train
(
x
,
y
);
w
=
join_cols
(
df
.
basis_vectors
(
0
),
uniform_matrix
<
double
>
(
1
,
1
,
-
df
.
b
));
true_w
=
1
,
0
,
1
;
dlog
<<
LINFO
<<
"w: "
<<
trans
(
w
);
dlog
<<
LINFO
<<
"error: "
<<
max
(
abs
(
w
-
true_w
));
DLIB_TEST
(
max
(
abs
(
w
-
true_w
))
<
1e-10
);
}
}
}
a
;
}
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