Commit d0a7f4cb authored by Davis King's avatar Davis King

Minor cleanup here and there.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403326
parent 8b6a5455
......@@ -68,35 +68,44 @@ namespace dlib
// find out the value of the largest norm of the elements in basis_samples.
const scalar_type max_norm = max(diag(kernel_matrix(kernel, basis_samples)));
// we will consider anything less than or equal to this number to be 0
const scalar_type eps = max_norm*std::numeric_limits<scalar_type>::epsilon();
// Copy all the basis_samples into basis but make sure we don't copy any samples
// that have length 0
for (long i = 0; i < basis_samples.size(); ++i)
{
const scalar_type norm = kernel(basis_samples(i), basis_samples(i));
if (norm > max_norm*std::numeric_limits<scalar_type>::epsilon())
if (norm > eps)
{
basis.push_back(basis_samples(i));
}
}
if (basis.size() == 0)
{
clear();
throw empirical_kernel_map_error("All basis_samples given to empirical_kernel_map::load() were zero vectors");
}
matrix<scalar_type,0,0,mem_manager_type> K(kernel_matrix(kernel, basis)), U,W,V;
if (svd2(false,true,K,U,W,V))
{
clear();
throw empirical_kernel_map_error("While loading empirical_kernel_map with data, SVD failed to converge.");
}
// we will consider anything less than or equal to this number to be 0
const scalar_type eps = max(W)*std::numeric_limits<scalar_type>::epsilon();
// now count how many elements of W are non-zero
const long num_not_zero = sum(W>eps);
// Really, this should never happen. But I'm checking for good measure.
if (num_not_zero == 0)
{
clear();
throw empirical_kernel_map_error("While loading empirical_kernel_map with data, SVD failed");
}
weights.set_size(num_not_zero, basis.size());
......
......@@ -32,10 +32,9 @@ namespace dlib
represent points in the kernel feature space defined by whatever kernel
is used with this object.
More precisely, to use this object you supply it with a particular kernel and
a set of basis samples. After that you can present it with new samples and it
will project them into the part of kernel feature space spanned by your basis
samples.
To use the empirical_kernel_map you supply it with a particular kernel and a set of
basis samples. After that you can present it with new samples and it will project
them into the part of kernel feature space spanned by your basis samples.
This means the empirical_kernel_map is a tool you can use to very easily kernelize
any algorithm that operates on column vectors. All you have to do is select a
......@@ -64,6 +63,13 @@ namespace dlib
kernel map from data given by the user.
!*/
empirical_kernel_map (
);
/*!
ensures
- this object is properly initialized
!*/
void clear (
);
/*!
......@@ -89,7 +95,7 @@ namespace dlib
subspace of the kernel feature space defined by the given kernel and the
given set of basis samples. So after this function has been called you
will be able to project sample_type objects into kernel feature space
and obtain the resulting vector as a normal column matrix.
and obtain the resulting vector as a regular column matrix.
throws
- empirical_kernel_map_error
This exception is thrown if we are unable to create a kernel map.
......@@ -167,10 +173,10 @@ namespace dlib
(i.e. the returned decision function computes dot products, in kernel feature space,
between vect and any argument you give it. Note also that this equality is exact, even
for sample_type objects not in the span of the basis samples.)
- DF.kernel_function == get_kernel()
- DF.b == 0
- DF.basis_vectors == these will be the basis samples given to the previous call to load(). Note
that it is possible for there to be fewer basis_vectors than basis samples given to load().
- DF.kernel_function == get_kernel()
- DF.b == 0
- DF.basis_vectors == these will be the basis samples given to the previous call to load(). Note
that it is possible for there to be fewer basis_vectors than basis samples given to load().
!*/
template <typename EXP>
......@@ -196,10 +202,10 @@ namespace dlib
approximation error. Note that all the basis samples are always within their
own span. So the equality is always exact for the samples given to the load()
function.
- DF.kernel_function == get_kernel()
- DF.b == dot(vect,vect)
- DF.basis_vectors == these will be the basis samples given to the previous call to load(). Note
that it is possible for there to be fewer basis_vectors than basis samples given to load().
- DF.kernel_function == get_kernel()
- DF.b == dot(vect,vect)
- DF.basis_vectors == these will be the basis samples given to the previous call to load(). Note
that it is possible for there to be fewer basis_vectors than basis samples given to load().
!*/
const projection_function<kernel_type> get_projection_function (
......
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