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
46bb6dc8
Commit
46bb6dc8
authored
Nov 17, 2013
by
Davis King
Browse files
Added code showing how to get the individual decision functions out of a
multiclass decision function object.
parent
1e67beb7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
132 additions
and
103 deletions
+132
-103
examples/multiclass_classification_ex.cpp
examples/multiclass_classification_ex.cpp
+132
-103
No files found.
examples/multiclass_classification_ex.cpp
View file @
46bb6dc8
...
...
@@ -42,6 +42,8 @@ void generate_data (
int
main
()
{
try
{
std
::
vector
<
sample_type
>
samples
;
std
::
vector
<
double
>
labels
;
...
...
@@ -125,7 +127,7 @@ int main()
*/
//
Finally, i
f you want to save a one_vs_one_decision_function to disk, you can do
//
I
f you want to save a one_vs_one_decision_function to disk, you can do
// so. However, you must declare what kind of decision functions it contains.
one_vs_one_decision_function
<
ovo_trainer
,
decision_function
<
poly_kernel
>
,
// This is the output of the poly_trainer
...
...
@@ -152,6 +154,33 @@ int main()
// Test df3 on the samples and labels and print the confusion matrix.
cout
<<
"test deserialized function:
\n
"
<<
test_multiclass_decision_function
(
df3
,
samples
,
labels
)
<<
endl
;
// Finally, if you want to get the binary classifiers from inside a multiclass decision
// function you can do it by calling get_binary_decision_functions() like so:
one_vs_one_decision_function
<
ovo_trainer
>::
binary_function_table
functs
;
functs
=
df
.
get_binary_decision_functions
();
cout
<<
"number of binary decision functions in df: "
<<
functs
.
size
()
<<
endl
;
// The functs object is a std::map which maps pairs of labels to binary decision
// functions. So we can access the individual decision functions like so:
decision_function
<
poly_kernel
>
df_1_2
=
any_cast
<
decision_function
<
poly_kernel
>
>
(
functs
[
make_unordered_pair
(
1
,
2
)]);
decision_function
<
rbf_kernel
>
df_1_3
=
any_cast
<
decision_function
<
rbf_kernel
>
>
(
functs
[
make_unordered_pair
(
1
,
3
)]);
// df_1_2 contains the binary decision function that votes for class 1 vs. 2.
// Similarly, df_1_3 contains the classifier that votes for 1 vs. 3.
// Note that the multiclass decision function doesn't know what kind of binary
// decision functions it contains. So we have to use any_cast to explicitly cast
// them back into the concrete type. If you make a mistake and try to any_cast a
// binary decision function into the wrong type of function any_cast will throw a
// bad_any_cast exception.
}
catch
(
std
::
exception
&
e
)
{
cout
<<
"exception thrown!"
<<
endl
;
cout
<<
e
.
what
()
<<
endl
;
}
}
// ----------------------------------------------------------------------------------------
...
...
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