Commit 7a83a30d authored by Davis King's avatar Davis King

Added the is_assignment_problem() and is_forced_assignment_problem() routines.

parent 381a73a2
...@@ -198,6 +198,74 @@ namespace dlib ...@@ -198,6 +198,74 @@ namespace dlib
return false; 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 < template <
......
...@@ -79,6 +79,55 @@ namespace dlib ...@@ -79,6 +79,55 @@ namespace dlib
its corresponding sample sequence) 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
!*/
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment