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
d71b2a08
Commit
d71b2a08
authored
Jun 18, 2013
by
Davis King
Browse files
merged
parents
c3909170
623c657c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
0 deletions
+27
-0
dlib/svm/structural_svm_problem.h
dlib/svm/structural_svm_problem.h
+27
-0
No files found.
dlib/svm/structural_svm_problem.h
View file @
d71b2a08
...
@@ -48,7 +48,10 @@ namespace dlib
...
@@ -48,7 +48,10 @@ namespace dlib
lru_count
.
clear
();
lru_count
.
clear
();
if
(
prob
->
get_max_cache_size
()
!=
0
)
if
(
prob
->
get_max_cache_size
()
!=
0
)
{
prob
->
get_truth_joint_feature_vector
(
idx
,
true_psi
);
prob
->
get_truth_joint_feature_vector
(
idx
,
true_psi
);
compact_sparse_vector
(
true_psi
);
}
}
}
void
get_truth_joint_feature_vector_cached
(
void
get_truth_joint_feature_vector_cached
(
...
@@ -106,6 +109,8 @@ namespace dlib
...
@@ -106,6 +109,8 @@ namespace dlib
if
(
prob
->
get_max_cache_size
()
==
0
)
if
(
prob
->
get_max_cache_size
()
==
0
)
return
;
return
;
compact_sparse_vector
(
out_psi
);
// if the cache is full
// if the cache is full
if
(
loss
.
size
()
>=
prob
->
get_max_cache_size
())
if
(
loss
.
size
()
>=
prob
->
get_max_cache_size
())
{
{
...
@@ -132,6 +137,28 @@ namespace dlib
...
@@ -132,6 +137,28 @@ namespace dlib
}
}
}
}
// Do nothing if T isn't actually a sparse vector
template
<
typename
T
>
void
compact_sparse_vector
(
T
&
)
const
{
}
template
<
typename
T
,
typename
U
,
typename
alloc
>
void
compact_sparse_vector
(
std
::
vector
<
std
::
pair
<
T
,
U
>
,
alloc
>&
vect
)
const
{
// If the sparse vector has more entires than dimensions then it must have some
// duplicate elements. So compact them using make_sparse_vector_inplace().
if
(
vect
.
size
()
>
(
unsigned
long
)
prob
->
get_num_dimensions
())
{
make_sparse_vector_inplace
(
vect
);
// make sure the vector doesn't use more RAM than is necessary
std
::
vector
<
std
::
pair
<
T
,
U
>
,
alloc
>
(
vect
).
swap
(
vect
);
}
}
const
structural_svm_problem
*
prob
;
const
structural_svm_problem
*
prob
;
long
sample_idx
;
long
sample_idx
;
...
...
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