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
46bb6dc8
Commit
46bb6dc8
authored
Nov 17, 2013
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added code showing how to get the individual decision functions out of a
multiclass decision function object.
parent
1e67beb7
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
1 deletion
+30
-1
multiclass_classification_ex.cpp
examples/multiclass_classification_ex.cpp
+30
-1
No files found.
examples/multiclass_classification_ex.cpp
View file @
46bb6dc8
...
@@ -42,6 +42,8 @@ void generate_data (
...
@@ -42,6 +42,8 @@ void generate_data (
int
main
()
int
main
()
{
{
try
{
std
::
vector
<
sample_type
>
samples
;
std
::
vector
<
sample_type
>
samples
;
std
::
vector
<
double
>
labels
;
std
::
vector
<
double
>
labels
;
...
@@ -125,7 +127,7 @@ int main()
...
@@ -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.
// so. However, you must declare what kind of decision functions it contains.
one_vs_one_decision_function
<
ovo_trainer
,
one_vs_one_decision_function
<
ovo_trainer
,
decision_function
<
poly_kernel
>
,
// This is the output of the poly_trainer
decision_function
<
poly_kernel
>
,
// This is the output of the poly_trainer
...
@@ -152,6 +154,33 @@ int main()
...
@@ -152,6 +154,33 @@ int main()
// Test df3 on the samples and labels and print the confusion matrix.
// 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
;
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