Commit ebf4de2b authored by Davis King's avatar Davis King

Added more overloads of randomly_subsample() that can operate on random_subset_selector

objects.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403648
parent db2f60b9
......@@ -267,6 +267,43 @@ namespace dlib
return subset;
}
// ----------------------------------------------------------------------------------------
template <
typename T
>
random_subset_selector<T> randomly_subsample (
const random_subset_selector<T>& samples,
unsigned long num
)
{
random_subset_selector<T> subset;
subset.set_max_size(num);
for (unsigned long i = 0; i < samples.size(); ++i)
subset.add(samples[i]);
return subset;
}
// ----------------------------------------------------------------------------------------
template <
typename T,
typename U
>
random_subset_selector<T> randomly_subsample (
const random_subset_selector<T>& samples,
unsigned long num,
const U& random_seed
)
{
random_subset_selector<T> subset;
subset.set_seed(cast_to_string(random_seed));
subset.set_max_size(num);
for (unsigned long i = 0; i < samples.size(); ++i)
subset.add(samples[i]);
return subset;
}
// ----------------------------------------------------------------------------------------
}
......
......@@ -283,6 +283,49 @@ namespace dlib
generator used by this function.
!*/
// ----------------------------------------------------------------------------------------
template <
typename T
>
random_subset_selector<T> randomly_subsample (
const random_subset_selector<T>& samples,
unsigned long num
);
/*!
ensures
- returns a random subset R such that:
- R contains a random subset of the given samples
- R.size() == min(num, samples.size())
- R.max_size() == num
- The random number generator used by this function will always be
initialized in the same way. I.e. this function will always pick
the same random subsample if called multiple times.
!*/
// ----------------------------------------------------------------------------------------
template <
typename T,
typename U
>
random_subset_selector<T> randomly_subsample (
const random_subset_selector<T>& samples,
unsigned long num,
const U& random_seed
);
/*!
requires
- random_seed must be convertible to a string by dlib::cast_to_string()
ensures
- returns a random subset R such that:
- R contains a random subset of the given samples
- R.size() == min(num, samples.size())
- R.max_size() == num
- The given random_seed will be used to initialize the random number
generator used by this function.
!*/
// ----------------------------------------------------------------------------------------
}
......
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