Commit 14ff48d3 authored by Davis King's avatar Davis King

Added the ability to compare kcentroid objects to each other

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402365
parent d7b506fa
...@@ -73,6 +73,33 @@ namespace dlib ...@@ -73,6 +73,33 @@ namespace dlib
bias = 0; 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() ( scalar_type operator() (
const sample_type& x const sample_type& x
) const ) const
......
...@@ -106,12 +106,23 @@ namespace dlib ...@@ -106,12 +106,23 @@ namespace dlib
- #samples_seen() == 0 - #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() ( scalar_type operator() (
const sample_type& x const sample_type& x
) const; ) const;
/*! /*!
ensures 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 current estimate of the centroid of the training samples given
to this object so far. to this object so far.
!*/ !*/
......
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