File: feature_ranking_abstract.h

package info (click to toggle)
mldemos 0.5.1-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 32,224 kB
  • ctags: 46,525
  • sloc: cpp: 306,887; ansic: 167,718; ml: 126; sh: 109; makefile: 2
file content (136 lines) | stat: -rw-r--r-- 5,661 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// Copyright (C) 2008  Davis E. King (davis@dlib.net)
// License: Boost Software License   See LICENSE.txt for the full license.
#undef DLIB_KERNEL_FEATURE_RANKINg_ABSTRACT_H_
#ifdef DLIB_KERNEL_FEATURE_RANKINg_ABSTRACT_H_

#include <vector>
#include <limits>

#include "svm_abstract.h"
#include "kcentroid_abstract.h"
#include "../is_kind.h"

namespace dlib
{

// ----------------------------------------------------------------------------------------

    template <
        typename kernel_type,
        typename sample_matrix_type,
        typename label_matrix_type
        >
    matrix<typename kernel_type::scalar_type> rank_features (
        const kcentroid<kernel_type>& kc,
        const sample_matrix_type& samples,
        const label_matrix_type& labels,
        const long num_features = samples(0).nr()
    );
    /*!
        requires
            - sample_matrix_type == a matrix or something convertible to a matrix via vector_to_matrix()
            - label_matrix_type  == a matrix or something convertible to a matrix via vector_to_matrix()
            - is_binary_classification_problem(samples, labels) == true
            - kc.train(samples(0)) must be a valid expression.  This means that
              kc must use a kernel type that is capable of operating on the
              contents of the samples matrix
            - 0 < num_features <= samples(0).nr()
        ensures
            - Let Class1 denote the centroid of all the samples with labels that are < 0
            - Let Class2 denote the centroid of all the samples with labels that are > 0
            - finds a ranking of the features where the best features come first.  This 
              function does this by computing the distance between the centroid of the Class1 
              samples and the Class2 samples in kernel defined feature space.
              Good features are then ones that result in the biggest separation between
              the two centroids of Class1 and Class2.
            - Uses the kc object to compute the centroids of the two classes
            - returns a ranking matrix R where:
                - R.nr() == num_features
                - r.nc() == 2
                - R(i,0) == the index of the ith best feature according to our ranking.
                  (e.g. samples(n)(R(0,0)) is the best feature from sample(n) and
                   samples(n)(R(1,0)) is the second best, samples(n)(R(2,0)) the
                   third best and so on)
                - R(i,1) == a number that indicates how much separation exists between 
                  the two centroids when features 0 through i are used.
    !*/

// ----------------------------------------------------------------------------------------

    template <
        typename sample_matrix_type,
        typename label_matrix_type
        >
    double find_gamma_with_big_centroid_gap (
        const sample_matrix_type& samples,
        const label_matrix_type& labels,
        double initial_gamma = 0.1,
        unsigned long num_sv = 40
    );
    /*!
        requires
            - initial_gamma > 0
            - num_sv > 0
            - is_binary_classification_problem(samples, labels) == true
        ensures
            - This is a function that tries to pick a reasonable default value for the gamma 
              parameter of the radial_basis_kernel.  It picks the parameter that gives the 
              largest separation between the centroids, in kernel feature space, of two classes 
              of data. It does this using the kcentroid object and it sets the kcentroid up 
              to use num_sv dictionary vectors.
            - This function does a search for the best gamma and the search starts with
              the value given by initial_gamma.  Better initial guesses will give 
              better results since the routine may get stuck in a local minima.
            - returns the value of gamma that results in the largest separation.
    !*/

// ----------------------------------------------------------------------------------------

    template <
        typename sample_matrix_type,
        typename label_matrix_type
        >
    double verbose_find_gamma_with_big_centroid_gap (
        const sample_matrix_type& samples,
        const label_matrix_type& labels,
        double initial_gamma = 0.1,
        unsigned long num_sv = 40
    );
    /*!
        requires
            - initial_gamma > 0
            - num_sv > 0
            - is_binary_classification_problem(samples, labels) == true
        ensures
            - This function does the same exact thing as the above find_gamma_with_big_centroid_gap()
              except that it is also verbose in the sense that it will print status messages to
              standard out during its processing.
    !*/

// ----------------------------------------------------------------------------------------

    template <
        typename vector_type
        >
    double compute_mean_squared_distance (
        const vector_type& samples
    );
    /*!
        requires
            - vector_type is something with an interface compatible with std::vector.  
              Additionally, it must in turn contain dlib::matrix types which contain 
              scalars such as float or double values.
            - for all valid i: is_vector(samples[i]) == true
        ensures
            - computes the average value of the squares of all the pairwise 
              distances between every element of samples.  
    !*/

// ----------------------------------------------------------------------------------------

}

#endif // DLIB_KERNEL_FEATURE_RANKINg_ABSTRACT_H_