Commit f02d09da authored by Davis King's avatar Davis King

Added is_sequence_segmentation_problem()

parent 4a527aa8
......@@ -198,6 +198,49 @@ namespace dlib
return false;
}
// ----------------------------------------------------------------------------------------
template <
typename sequence_type
>
bool is_sequence_segmentation_problem (
const std::vector<sequence_type>& samples,
const std::vector<std::vector<std::pair<unsigned long,unsigned long> > >& segments
)
{
if (is_learning_problem(samples, segments))
{
for (unsigned long i = 0; i < samples.size(); ++i)
{
// Make sure the segments are inside samples[i] and don't overlap with each
// other.
std::vector<bool> hits(samples[i].size(), false);
for (unsigned long j = 0; j < segments[i].size(); ++j)
{
const unsigned long begin = segments[i][j].first;
const unsigned long end = segments[i][j].second;
// if the segment is outside the sequence
if (end > samples[i].size())
return false;
if (begin > end)
return false;
// check for overlap
for (unsigned long k = begin; k < end; ++k)
{
if (hits[k])
return false;
hits[k] = true;
}
}
}
return true;
}
return false;
}
// ----------------------------------------------------------------------------------------
template <
......
......@@ -40,6 +40,8 @@ namespace dlib
- x.size() > 0
!*/
// ----------------------------------------------------------------------------------------
template <
typename T,
typename U
......@@ -62,6 +64,8 @@ namespace dlib
- x_labels(i) == -1 or +1
!*/
// ----------------------------------------------------------------------------------------
template <
typename sequence_type
>
......@@ -79,6 +83,33 @@ namespace dlib
its corresponding sample sequence)
!*/
// ----------------------------------------------------------------------------------------
template <
typename sequence_type
>
bool is_sequence_segmentation_problem (
const std::vector<sequence_type>& samples,
const std::vector<std::vector<std::pair<unsigned long,unsigned long> > >& segments
);
/*!
ensures
- returns true if all of the following are true and false otherwise:
- is_learning_problem(samples, segments) == true
- for all valid i:
- for all valid j:
- We interpret segments[i][j] as defining a half open range
starting with segments[i][j].first and ending just before
segments[i][j].second.
- segments[i][j].first <= segments[i][j].second
- segments[i][j].second <= samples[i].size()
(i.e. Each segment must be contained within its associated sequence)
- segments[i][j] does not overlap with any of the other ranges in
segments[i].
!*/
// ----------------------------------------------------------------------------------------
template <
typename lhs_type,
typename rhs_type
......@@ -106,6 +137,8 @@ namespace dlib
in samples[i].second.
!*/
// ----------------------------------------------------------------------------------------
template <
typename lhs_type,
typename rhs_type
......
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