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
3a5f99f4
Commit
3a5f99f4
authored
May 06, 2012
by
Davis King
Browse files
Updated the interface to the structural_graph_labeling_trainer so the user
can set the per class loss to whatever they want.
parent
42c123f2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
84 additions
and
0 deletions
+84
-0
dlib/svm/structural_graph_labeling_trainer.h
dlib/svm/structural_graph_labeling_trainer.h
+42
-0
dlib/svm/structural_graph_labeling_trainer_abstract.h
dlib/svm/structural_graph_labeling_trainer_abstract.h
+42
-0
No files found.
dlib/svm/structural_graph_labeling_trainer.h
View file @
3a5f99f4
...
@@ -32,6 +32,8 @@ namespace dlib
...
@@ -32,6 +32,8 @@ namespace dlib
eps
=
0.1
;
eps
=
0.1
;
num_threads
=
2
;
num_threads
=
2
;
max_cache_size
=
40
;
max_cache_size
=
40
;
loss_pos
=
1.0
;
loss_neg
=
1.0
;
}
}
void
set_num_threads
(
void
set_num_threads
(
...
@@ -124,6 +126,42 @@ namespace dlib
...
@@ -124,6 +126,42 @@ namespace dlib
return
C
;
return
C
;
}
}
void
set_loss_on_positive_class
(
double
loss
)
{
// make sure requires clause is not broken
DLIB_ASSERT
(
loss
>=
0
,
"
\t
structural_graph_labeling_trainer::set_loss_on_positive_class()"
<<
"
\n\t
Invalid inputs were given to this function."
<<
"
\n\t
loss: "
<<
loss
<<
"
\n\t
this: "
<<
this
);
loss_pos
=
loss
;
}
void
set_loss_on_negative_class
(
double
loss
)
{
// make sure requires clause is not broken
DLIB_ASSERT
(
loss
>=
0
,
"
\t
structural_graph_labeling_trainer::set_loss_on_negative_class()"
<<
"
\n\t
Invalid inputs were given to this function."
<<
"
\n\t
loss: "
<<
loss
<<
"
\n\t
this: "
<<
this
);
loss_neg
=
loss
;
}
double
get_loss_on_negative_class
(
)
const
{
return
loss_neg
;
}
double
get_loss_on_positive_class
(
)
const
{
return
loss_pos
;
}
template
<
template
<
typename
graph_type
typename
graph_type
>
>
...
@@ -150,6 +188,8 @@ namespace dlib
...
@@ -150,6 +188,8 @@ namespace dlib
prob
.
set_c
(
C
);
prob
.
set_c
(
C
);
prob
.
set_epsilon
(
eps
);
prob
.
set_epsilon
(
eps
);
prob
.
set_max_cache_size
(
max_cache_size
);
prob
.
set_max_cache_size
(
max_cache_size
);
prob
.
set_loss_on_positive_class
(
loss_pos
);
prob
.
set_loss_on_negative_class
(
loss_neg
);
matrix
<
double
,
0
,
1
>
w
;
matrix
<
double
,
0
,
1
>
w
;
solver
(
prob
,
w
,
prob
.
get_num_edge_weights
());
solver
(
prob
,
w
,
prob
.
get_num_edge_weights
());
...
@@ -203,6 +243,8 @@ namespace dlib
...
@@ -203,6 +243,8 @@ namespace dlib
bool
verbose
;
bool
verbose
;
unsigned
long
num_threads
;
unsigned
long
num_threads
;
unsigned
long
max_cache_size
;
unsigned
long
max_cache_size
;
double
loss_pos
;
double
loss_neg
;
};
};
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
...
...
dlib/svm/structural_graph_labeling_trainer_abstract.h
View file @
3a5f99f4
...
@@ -48,6 +48,8 @@ namespace dlib
...
@@ -48,6 +48,8 @@ namespace dlib
- #get_epsilon() == 0.1
- #get_epsilon() == 0.1
- #get_num_threads() == 2
- #get_num_threads() == 2
- #get_max_cache_size() == 40
- #get_max_cache_size() == 40
- #get_loss_on_positive_class() == 1.0
- #get_loss_on_negative_class() == 1.0
!*/
!*/
void
set_num_threads
(
void
set_num_threads
(
...
@@ -159,6 +161,46 @@ namespace dlib
...
@@ -159,6 +161,46 @@ namespace dlib
better generalization.
better generalization.
!*/
!*/
void
set_loss_on_positive_class
(
double
loss
);
/*!
requires
- loss >= 0
ensures
- #get_loss_on_positive_class() == loss
!*/
void
set_loss_on_negative_class
(
double
loss
);
/*!
requires
- loss >= 0
ensures
- #get_loss_on_negative_class() == loss
!*/
double
get_loss_on_positive_class
(
)
const
;
/*!
ensures
- returns the loss incurred when a graph node which is supposed to have
a label of true gets misclassified. This value controls how much we care
about correctly classifying nodes which should be labeled as true. Larger
loss values indicate that we care more strongly than smaller values.
!*/
double
get_loss_on_negative_class
(
)
const
;
/*!
ensures
- returns the loss incurred when a graph node which is supposed to have
a label of false gets misclassified. This value controls how much we care
about correctly classifying nodes which should be labeled as false. Larger
loss values indicate that we care more strongly than smaller values.
!*/
template
<
template
<
typename
graph_type
typename
graph_type
>
>
...
...
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