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
7a83a30d
Commit
7a83a30d
authored
Dec 03, 2011
by
Davis King
Browse files
Added the is_assignment_problem() and is_forced_assignment_problem() routines.
parent
381a73a2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
117 additions
and
0 deletions
+117
-0
dlib/svm/svm.h
dlib/svm/svm.h
+68
-0
dlib/svm/svm_abstract.h
dlib/svm/svm_abstract.h
+49
-0
No files found.
dlib/svm/svm.h
View file @
7a83a30d
...
...
@@ -198,6 +198,74 @@ namespace dlib
return
false
;
}
// ----------------------------------------------------------------------------------------
template
<
typename
lhs_type
,
typename
rhs_type
>
bool
is_assignment_problem
(
const
std
::
vector
<
std
::
pair
<
std
::
vector
<
lhs_type
>
,
std
::
vector
<
rhs_type
>
>
>&
samples
,
const
std
::
vector
<
std
::
vector
<
long
>
>&
labels
)
{
std
::
vector
<
bool
>
seen_label
;
if
(
is_learning_problem
(
samples
,
labels
))
{
for
(
unsigned
long
i
=
0
;
i
<
samples
.
size
();
++
i
)
{
if
(
samples
[
i
].
first
.
size
()
!=
labels
[
i
].
size
())
return
false
;
seen_label
.
assign
(
samples
[
i
].
second
.
size
(),
false
);
for
(
unsigned
long
j
=
0
;
j
<
labels
[
i
].
size
();
++
j
)
{
if
(
!
(
-
1
<=
labels
[
i
][
j
]
&&
labels
[
i
][
j
]
<
(
long
)
samples
[
i
].
second
.
size
()))
return
false
;
if
(
labels
[
i
][
j
]
!=
-
1
)
{
// check label uniqueness
if
(
seen_label
[
labels
[
i
][
j
]])
return
false
;
seen_label
[
labels
[
i
][
j
]]
=
true
;
}
}
}
return
true
;
}
return
false
;
}
// ----------------------------------------------------------------------------------------
template
<
typename
lhs_type
,
typename
rhs_type
>
bool
is_forced_assignment_problem
(
const
std
::
vector
<
std
::
pair
<
std
::
vector
<
lhs_type
>
,
std
::
vector
<
rhs_type
>
>
>&
samples
,
const
std
::
vector
<
std
::
vector
<
long
>
>&
labels
)
{
if
(
is_assignment_problem
(
samples
,
labels
))
{
for
(
unsigned
long
i
=
0
;
i
<
samples
.
size
();
++
i
)
{
const
unsigned
long
N
=
sum
(
vector_to_matrix
(
labels
[
i
])
!=
-
1
);
if
(
std
::
min
(
samples
[
i
].
first
.
size
(),
samples
[
i
].
second
.
size
())
!=
N
)
return
false
;
}
return
true
;
}
return
false
;
}
// ----------------------------------------------------------------------------------------
template
<
...
...
dlib/svm/svm_abstract.h
View file @
7a83a30d
...
...
@@ -79,6 +79,55 @@ namespace dlib
its corresponding sample sequence)
!*/
template
<
typename
lhs_type
,
typename
rhs_type
>
bool
is_assignment_problem
(
const
std
::
vector
<
std
::
pair
<
std
::
vector
<
lhs_type
>
,
std
::
vector
<
rhs_type
>
>
>&
samples
,
const
std
::
vector
<
std
::
vector
<
long
>
>&
labels
);
/*!
ensures
- Note that an assignment problem is a task to associate each element of samples[i].first
to an element of samples[i].second, or to indicate that the element doesn't associate
with anything. Therefore, labels[i] should contain the association information for
samples[i].
- This function returns true if all of the following are true and false otherwise:
- is_learning_problem(samples, labels) == true
- for all valid i:
- samples[i].first.size() == labels[i].size()
- for all valid j:
-1 <= labels[i][j] < samples[i].second.size()
(a value of -1 indicates that samples[i].first[j] isn't associated with anything,
all other values indicate the associating element of samples[i].second)
- All elements of labels[i] which are not equal to -1 are unique. That is,
multiple elements of samples[i].first can't associate to the same element
in samples[i].second.
!*/
template
<
typename
lhs_type
,
typename
rhs_type
>
bool
is_forced_assignment_problem
(
const
std
::
vector
<
std
::
pair
<
std
::
vector
<
lhs_type
>
,
std
::
vector
<
rhs_type
>
>
>&
samples
,
const
std
::
vector
<
std
::
vector
<
long
>
>&
labels
);
/*!
ensures
- A regular assignment problem is allowed to indicate that all elements of
samples[i].first don't associate to anything. However, a forced assignment
problem is required to always associate an element of samples[i].first to
something in samples[i].second if there is an element of samples[i].second
that hasn't already been associated to something.
- This function returns true if all of the following are true and false otherwise:
- is_assignment_problem(samples, labels) == true
- for all valid i:
- let N denote the number of elements in labels[i] that are not equal to -1.
- min(samples[i].first.size(), samples[i].second.size()) == N
!*/
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
...
...
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