Added another overload to kernel_matrix() so it can work with random_subset_selector

objects.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403810
This commit is contained in:
Davis King 2010-08-15 13:09:59 +00:00
parent dceac7e9c4
commit c01d94b7bc
2 changed files with 19 additions and 3 deletions

View File

@ -7,6 +7,7 @@
#include "kernel_matrix_abstract.h" #include "kernel_matrix_abstract.h"
#include "../matrix.h" #include "../matrix.h"
#include "../algs.h" #include "../algs.h"
#include "../statistics/random_subset_selector.h"
namespace dlib namespace dlib
{ {
@ -23,6 +24,12 @@ namespace dlib
return m(i); return m(i);
} }
template <typename kernel_type, typename T, typename Rand_type>
inline const T& access ( const random_subset_selector<T,Rand_type>& m, long i)
{
return m[i];
}
template <typename kernel_type, typename T, typename alloc> template <typename kernel_type, typename T, typename alloc>
inline const T& access ( const std::vector<T,alloc>& m, long i) inline const T& access ( const std::vector<T,alloc>& m, long i)
{ {
@ -52,6 +59,12 @@ namespace dlib
return m.size(); return m.size();
} }
template <typename kernel_type, typename T, typename Rand_type>
inline unsigned long size ( const random_subset_selector<T,Rand_type>& m)
{
return m.size();
}
template <typename kernel_type, typename T, typename alloc> template <typename kernel_type, typename T, typename alloc>
inline unsigned long size ( const std::vector<T,alloc>& m) inline unsigned long size ( const std::vector<T,alloc>& m)
{ {

View File

@ -25,7 +25,8 @@ namespace dlib
requires requires
- kernel == a kernel function object as defined by the file dlib/svm/kernel_abstract.h. - kernel == a kernel function object as defined by the file dlib/svm/kernel_abstract.h.
This kernel must also be capable of operating on the contents of v. This kernel must also be capable of operating on the contents of v.
- V == dlib::matrix, std::vector, dlib::std_vector_c, or kernel_type::sample_type. - V == dlib::matrix, std::vector, dlib::std_vector_c, dlib::random_subset_selector, or
kernel_type::sample_type.
- if (V is a dlib::matrix) then - if (V is a dlib::matrix) then
- is_vector(v) == true - is_vector(v) == true
ensures ensures
@ -58,8 +59,10 @@ namespace dlib
requires requires
- kernel == a kernel function object as defined by the file dlib/svm/kernel_abstract.h - kernel == a kernel function object as defined by the file dlib/svm/kernel_abstract.h
This kernel must also be capable of operating on the contents of v1 and v2. This kernel must also be capable of operating on the contents of v1 and v2.
- V1 == dlib::matrix, std::vector, dlib::std_vector_c, or kernel_type::sample_type. - V1 == dlib::matrix, std::vector, dlib::std_vector_c, dlib::random_subset_selector, or
- V2 == dlib::matrix, std::vector, dlib::std_vector_c, or kernel_type::sample_type. kernel_type::sample_type.
- V2 == dlib::matrix, std::vector, dlib::std_vector_c, dlib::random_subset_selector, or
kernel_type::sample_type.
- if (V1 is a dlib::matrix) then - if (V1 is a dlib::matrix) then
- is_vector(v1) == true - is_vector(v1) == true
- if (V2 is a dlib::matrix) then - if (V2 is a dlib::matrix) then