mirror of
https://github.com/davisking/dlib.git
synced 2024-11-01 10:14:53 +08:00
Added some overloads of the randomize_samples() functions to take
std vector objects and to take just one vector of things without labels as well. --HG-- extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402368
This commit is contained in:
parent
828f7bbb87
commit
f870b052d7
@ -14,6 +14,7 @@
|
||||
#include "../std_allocator.h"
|
||||
#include "function.h"
|
||||
#include "kernel.h"
|
||||
#include "../enable_if.h"
|
||||
|
||||
namespace dlib
|
||||
{
|
||||
@ -1123,7 +1124,7 @@ namespace dlib
|
||||
typename T,
|
||||
typename U
|
||||
>
|
||||
void randomize_samples (
|
||||
typename enable_if<is_matrix<T>,void>::type randomize_samples (
|
||||
T& t,
|
||||
U& u
|
||||
)
|
||||
@ -1147,6 +1148,90 @@ namespace dlib
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
template <
|
||||
typename T,
|
||||
typename U
|
||||
>
|
||||
typename disable_if<is_matrix<T>,void>::type randomize_samples (
|
||||
T& t,
|
||||
U& u
|
||||
)
|
||||
{
|
||||
rand::kernel_1a r;
|
||||
|
||||
long n = t.size()-1;
|
||||
while (n > 0)
|
||||
{
|
||||
// put a random integer into idx
|
||||
unsigned long idx = r.get_random_32bit_number();
|
||||
|
||||
// make idx be less than n
|
||||
idx %= n;
|
||||
|
||||
// swap our randomly selected index into the n position
|
||||
exchange(t[idx], t[n]);
|
||||
exchange(u[idx], u[n]);
|
||||
|
||||
--n;
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
template <
|
||||
typename T
|
||||
>
|
||||
typename enable_if<is_matrix<T>,void>::type randomize_samples (
|
||||
T& t
|
||||
)
|
||||
{
|
||||
rand::kernel_1a r;
|
||||
|
||||
long n = t.nr()-1;
|
||||
while (n > 0)
|
||||
{
|
||||
// put a random integer into idx
|
||||
unsigned long idx = r.get_random_32bit_number();
|
||||
|
||||
// make idx be less than n
|
||||
idx %= n;
|
||||
|
||||
// swap our randomly selected index into the n position
|
||||
exchange(t(idx), t(n));
|
||||
|
||||
--n;
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
template <
|
||||
typename T
|
||||
>
|
||||
typename disable_if<is_matrix<T>,void>::type randomize_samples (
|
||||
T& t
|
||||
)
|
||||
{
|
||||
rand::kernel_1a r;
|
||||
|
||||
long n = t.size()-1;
|
||||
while (n > 0)
|
||||
{
|
||||
// put a random integer into idx
|
||||
unsigned long idx = r.get_random_32bit_number();
|
||||
|
||||
// make idx be less than n
|
||||
idx %= n;
|
||||
|
||||
// swap our randomly selected index into the n position
|
||||
exchange(t[idx], t[n]);
|
||||
|
||||
--n;
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
}
|
||||
|
@ -201,6 +201,60 @@ namespace dlib
|
||||
- #labels(r) == labels(i)
|
||||
!*/
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
template <
|
||||
typename T
|
||||
>
|
||||
void randomize_samples (
|
||||
T& samples
|
||||
);
|
||||
/*!
|
||||
requires
|
||||
- T == a matrix object that contains a swappable type
|
||||
- samples.nc() == 1
|
||||
ensures
|
||||
- randomizes the order of the elements inside samples
|
||||
!*/
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
template <
|
||||
typename T,
|
||||
typename U
|
||||
>
|
||||
void randomize_samples (
|
||||
T& samples,
|
||||
U& labels
|
||||
);
|
||||
/*!
|
||||
requires
|
||||
- T == an object compatible with std::vector that contains a swappable type
|
||||
- U == an object compatible with std::vector that contains a swappable type
|
||||
- samples.size() == labels.size()
|
||||
ensures
|
||||
- randomizes the order of the samples and labels but preserves
|
||||
the pairing between each sample and its label
|
||||
- for all valid i:
|
||||
- let r == the random index samples[i] was moved to. then:
|
||||
- #labels[r] == labels[i]
|
||||
!*/
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
template <
|
||||
typename T
|
||||
>
|
||||
void randomize_samples (
|
||||
T& samples
|
||||
);
|
||||
/*!
|
||||
requires
|
||||
- T == an object compatible with std::vector that contains a swappable type
|
||||
ensures
|
||||
- randomizes the order of the elements inside samples
|
||||
!*/
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user