Added a stddev() for matrix objects.

This commit is contained in:
Davis King 2012-10-01 21:34:10 -04:00
parent daecb0ec85
commit e2fdff8ca5
3 changed files with 23 additions and 0 deletions

View File

@ -1767,6 +1767,18 @@ namespace dlib
}
}
// ----------------------------------------------------------------------------------------
template <
typename EXP
>
const typename matrix_exp<EXP>::type stddev (
const matrix_exp<EXP>& m
)
{
return std::sqrt(variance(m));
}
// ----------------------------------------------------------------------------------------
// this is a workaround for a bug in visual studio 7.1

View File

@ -1541,6 +1541,16 @@ namespace dlib
(i.e. 1.0/(m.nr()*m.nc() - 1)*(sum of all pow(m(i,j) - mean(m),2)))
!*/
// ----------------------------------------------------------------------------------------
const matrix_exp::type stddev (
const matrix_exp& m
);
/*!
ensures
- returns std::sqrt(variance(m))
!*/
// ----------------------------------------------------------------------------------------
const matrix covariance (

View File

@ -299,6 +299,7 @@ namespace
}
DLIB_TEST(std::abs(variance(vector_to_matrix(a)) - rs1.variance()) < 1e-13);
DLIB_TEST(std::abs(stddev(vector_to_matrix(a)) - rs1.stddev()) < 1e-13);
DLIB_TEST(std::abs(mean(vector_to_matrix(a)) - rs1.mean()) < 1e-13);
for (int i = 10; i < 20; ++i)