Added the ability to compare kcentroid objects to each other

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402365
This commit is contained in:
Davis King 2008-07-03 22:56:25 +00:00
parent d7b506fa43
commit 14ff48d30c
2 changed files with 39 additions and 1 deletions

View File

@ -73,6 +73,33 @@ namespace dlib
bias = 0;
}
scalar_type operator() (
const kcentroid& x
) const
{
// make sure requires clause is not broken
DLIB_ASSERT(x.get_kernel() == get_kernel(),
"\tscalar_type kcentroid::operator()(const kcentroid& x)"
<< "\n\tYou can only compare two kcentroid objects if they use the same kernel"
<< "\n\tthis: " << this
);
scalar_type temp = 0;
for (unsigned long i = 0; i < alpha.size(); ++i)
{
for (unsigned long j = 0; j < x.alpha.size(); ++j)
{
temp += alpha[i]*x.alpha[j]*kernel(dictionary[i], x.dictionary[j]);
}
}
temp = x.bias + bias - 2*temp;
if (temp > 0)
return std::sqrt(temp);
else
return 0;
}
scalar_type operator() (
const sample_type& x
) const

View File

@ -106,12 +106,23 @@ namespace dlib
- #samples_seen() == 0
!*/
scalar_type operator() (
const kcentroid& x
) const;
/*!
requires
- x.get_kernel() == get_kernel()
ensures
- returns the distance in kernel feature space between this centroid and the
centroid represented by x.
!*/
scalar_type operator() (
const sample_type& x
) const;
/*!
ensures
- returns the distance in feature space between the sample x and the
- returns the distance in kernel feature space between the sample x and the
current estimate of the centroid of the training samples given
to this object so far.
!*/