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