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
374459b4
Commit
374459b4
authored
Jul 29, 2012
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored this code a little
parent
7e28ce5e
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
11 deletions
+33
-11
structural_svm_graph_labeling_problem.h
dlib/svm/structural_svm_graph_labeling_problem.h
+33
-11
No files found.
dlib/svm/structural_svm_graph_labeling_problem.h
View file @
374459b4
...
...
@@ -333,9 +333,9 @@ namespace dlib
// Include a loss augmentation so that we will get the proper loss augmented
// max when we use find_max_factor_graph_potts() below.
if
(
labels
[
idx
][
i
])
g
.
node
(
i
).
data
-=
loss_pos
;
g
.
node
(
i
).
data
-=
get_loss_for_sample
(
idx
,
i
,
!
labels
[
idx
][
i
])
;
else
g
.
node
(
i
).
data
+=
loss_neg
;
g
.
node
(
i
).
data
+=
get_loss_for_sample
(
idx
,
i
,
!
labels
[
idx
][
i
])
;
for
(
unsigned
long
n
=
0
;
n
<
g
.
node
(
i
).
number_of_neighbors
();
++
n
)
{
...
...
@@ -360,20 +360,42 @@ namespace dlib
loss
=
0
;
for
(
unsigned
long
i
=
0
;
i
<
labeling
.
size
();
++
i
)
{
const
bool
true_label
=
labels
[
idx
][
i
];
const
bool
pred_label
=
(
labeling
[
i
]
!=
0
);
bool_labeling
.
push_back
(
pred_label
);
if
(
true_label
!=
pred_label
)
const
bool
predicted_label
=
(
labeling
[
i
]
!=
0
);
bool_labeling
.
push_back
(
predicted_label
);
loss
+=
get_loss_for_sample
(
idx
,
i
,
predicted_label
);
}
// compute psi
get_joint_feature_vector
(
samp
,
bool_labeling
,
psi
);
}
double
get_loss_for_sample
(
long
sample_idx
,
long
node_idx
,
bool
predicted_label
)
const
/*!
requires
- 0 <= sample_idx < labels.size()
- 0 <= node_idx < labels[sample_idx].size()
ensures
- returns the loss incurred for predicting that the node
samples[sample_idx].node(node_idx) has a label of predicted_label.
!*/
{
const
bool
true_label
=
labels
[
sample_idx
][
node_idx
];
if
(
true_label
!=
predicted_label
)
{
if
(
true_label
==
true
)
loss
+=
loss_pos
;
return
loss_pos
;
else
loss
+=
loss_neg
;
return
loss_neg
;
}
else
{
// no loss for making the correct prediction.
return
0
;
}
// compute psi
get_joint_feature_vector
(
samp
,
bool_labeling
,
psi
);
}
const
dlib
::
array
<
sample_type
>&
samples
;
...
...
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