Commit a5afa68f authored by Davis King's avatar Davis King

Added a function to compute projection error into the linearly_independent_subset_finder.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403675
parent cf04ff5f
...@@ -122,6 +122,31 @@ namespace dlib ...@@ -122,6 +122,31 @@ namespace dlib
K.set_size(0,0); K.set_size(0,0);
} }
scalar_type projection_error (
const sample_type& x
) const
{
const scalar_type kx = kernel(x,x);
if (dictionary.size() == 0)
{
return kx;
}
else
{
// fill in k
k.set_size(dictionary.size());
for (long r = 0; r < k.nr(); ++r)
k(r) = kernel(x,dictionary[r]);
// compute the error we would have if we approximated the new x sample
// with the dictionary. That is, do the ALD test from the KRLS paper.
a = K_inv*k;
scalar_type delta = kx - trans(k)*a;
return delta;
}
}
bool add ( bool add (
const sample_type& x const sample_type& x
) )
...@@ -157,7 +182,7 @@ namespace dlib ...@@ -157,7 +182,7 @@ namespace dlib
scalar_type delta = kx - trans(k)*a; scalar_type delta = kx - trans(k)*a;
// if this new vector is approximately linearly independent of the vectors // if this new vector is approximately linearly independent of the vectors
// in our dictionary. Or if our dictionary just isn't full yet. // in our dictionary.
if (delta > min_strength && delta > min_tolerance) if (delta > min_strength && delta > min_tolerance)
{ {
if (dictionary.size() == my_max_dictionary_size) if (dictionary.size() == my_max_dictionary_size)
...@@ -366,9 +391,9 @@ namespace dlib ...@@ -366,9 +391,9 @@ namespace dlib
// temp variables here just so we don't have to reconstruct them over and over. Thus, // temp variables here just so we don't have to reconstruct them over and over. Thus,
// they aren't really part of the state of this object. // they aren't really part of the state of this object.
matrix<scalar_type,0,1,mem_manager_type> a, a2; mutable matrix<scalar_type,0,1,mem_manager_type> a, a2;
matrix<scalar_type,0,1,mem_manager_type> k, k2; mutable matrix<scalar_type,0,1,mem_manager_type> k, k2;
matrix<scalar_type,0,0,mem_manager_type> temp; mutable matrix<scalar_type,0,0,mem_manager_type> temp;
}; };
......
...@@ -145,6 +145,20 @@ namespace dlib ...@@ -145,6 +145,20 @@ namespace dlib
- returns false - returns false
!*/ !*/
scalar_type projection_error (
const sample_type& x
) const;
/*!
ensures
- returns the squared distance between x and the subspace spanned by
the set of dictionary vectors. (e.g. this is the same number that
gets returned by the empirical_kernel_map::project() function's
projection_error argument when the ekm is loaded with the dictionary
vectors.)
- Note that if the dictionary is empty then the return value is
equal to get_kernel(x,x).
!*/
void swap ( void swap (
linearly_independent_subset_finder& item linearly_independent_subset_finder& item
); );
......
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