Added tests and slight refinements

This commit is contained in:
Davis King 2013-06-15 13:37:26 -04:00
parent a0797fd132
commit ec6be63e8d
3 changed files with 44 additions and 1 deletions

View File

@ -824,7 +824,9 @@ namespace dlib
{
// make sure requires clause is not broken
DLIB_ASSERT(is_col_vector(x) && (x_vector_size() == 0 || x.size() == x_vector_size()) &&
is_col_vector(y) && (y_vector_size() == 0 || y.size() == y_vector_size()),
is_col_vector(y) && (y_vector_size() == 0 || y.size() == y_vector_size()) &&
x.size() != 0 &&
y.size() != 0,
"\t void running_cross_covariance::add()"
<< "\n\t Invalid inputs were given to this function"
<< "\n\t is_col_vector(x): " << is_col_vector(x)

View File

@ -602,6 +602,8 @@ namespace dlib
requires
- is_col_vector(x) == true
- is_col_vector(y) == true
- x.size() != 0
- y.size() != 0
- if (x_vector_size() != 0) then
- x.size() == x_vector_size()
- if (y_vector_size() != 0) then

View File

@ -133,6 +133,44 @@ namespace
}
}
void test_running_cross_covariance ()
{
running_cross_covariance<matrix<double> > rcc1, rcc2;
matrix<double,0,1> xm, ym;
const int num = 40;
dlib::rand rnd;
for (int i = 0; i < num; ++i)
{
matrix<double,0,1> x = randm(4,1,rnd);
matrix<double,0,1> y = randm(4,1,rnd);
xm += x/num;
ym += y/num;
if (i < 15)
rcc1.add(x,y);
else
rcc2.add(x,y);
}
rnd.clear();
matrix<double> cov;
for (int i = 0; i < num; ++i)
{
matrix<double,0,1> x = randm(4,1,rnd);
matrix<double,0,1> y = randm(4,1,rnd);
cov += (x-xm)*trans(y-ym);
}
cov /= num-1;
running_cross_covariance<matrix<double> > rcc = rcc1 + rcc2;
DLIB_TEST(max(abs(rcc.covariance_xy()-cov)) < 1e-14);
DLIB_TEST(max(abs(rcc.mean_x()-xm)) < 1e-14);
DLIB_TEST(max(abs(rcc.mean_y()-ym)) < 1e-14);
}
void test_running_covariance (
)
{
@ -459,6 +497,7 @@ namespace
test_random_subset_selector();
test_random_subset_selector2();
test_running_covariance();
test_running_cross_covariance();
test_running_stats();
test_skewness_and_kurtosis_1();
test_skewness_and_kurtosis_2();