Commit 2b0ae8ad authored by Davis King's avatar Davis King

Changed the projection_error to be squared distance rather than just

straight euclidean distance.  I did this because the kcentroid,
linearly_independent_subset_finder, and krls object's tolerance
parameter is also a measure of squared projection distance and
it is nice if all of these things are the same.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403407
parent 89d09da1
......@@ -267,9 +267,12 @@ namespace dlib
temp1 = kernel_matrix(kernel, basis, samp);
temp2 = weights*temp1;
// The std::abs is here because rounding error could make the expresison negative
// which would be bad since sqrt() would get upset.
projection_error = std::sqrt(std::abs( kernel(samp,samp) - dot(temp2,temp2)));
projection_error = std::abs( kernel(samp,samp) - dot(temp2,temp2));
// Rounding error could make the expression slightly negative which is an impossible result
// since it measures a distance. Just force it to be zero in that case.
if (projection_error < 0)
projection_error = 0;
return temp2;
}
......
......@@ -195,18 +195,19 @@ namespace dlib
!*/
const matrix<scalar_type,0,1,mem_manager_type>& project (
const sample_type& sample,
const sample_type& samp,
scalar_type& projection_error
) const;
/*!
requires
- out_vector_size() != 0
ensures
- This function returns project(sample)
- This function returns project(samp)
(i.e. it returns the same thing as the above project() function)
- #projection_error == the distance between the point sample gets projected
onto and sample's true image in kernel feature space. That is, this value
is equal to: convert_to_distance_function(project(sample))(sample)
- #projection_error == the square of the distance between the point samp
gets projected onto and samp's true image in kernel feature space.
That is, this value is equal to:
pow(convert_to_distance_function(project(samp))(samp),2)
!*/
template <typename EXP>
......
......@@ -67,7 +67,7 @@ namespace
for (int i = 0; i < samples.size(); ++i)
{
ekm.project(samples[i], err);
DLIB_TEST_MSG(abs(err) < 1e-7, abs(err));
DLIB_TEST_MSG(abs(err) < 1e-13, abs(err));
}
......@@ -111,6 +111,8 @@ namespace
{
sample_type test_point = i*randm(5,1,rnd);
ekm.project(test_point, err);
// turn into normal distance rather than squared distance
err = sqrt(err);
dlog << LTRACE << "projection error: " << err;
distance_function<kernel_type> df = ekm.convert_to_distance_function(ekm.project(test_point));
......
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