1 // Copyright (C) 2011  Davis E. King (davis@dlib.net)
2 // License: Boost Software License   See LICENSE.txt for the full license.
3 #undef DLIB_CREATE_RANDOM_PROJECTION_HAsH_ABSTRACT_Hh_
4 #ifdef DLIB_CREATE_RANDOM_PROJECTION_HAsH_ABSTRACT_Hh_
5 
6 #include "projection_hash_abstract.h"
7 #include "../rand.h"
8 
9 namespace dlib
10 {
11 
12 // ----------------------------------------------------------------------------------------
13 
14     template <
15         typename vector_type
16         >
17     projection_hash create_random_projection_hash (
18         const vector_type& v,
19         const int bits,
20         dlib::rand& rnd
21     );
22     /*!
23         requires
24             - 0 < bits <= 32
25             - v.size() > 1
26             - vector_type == a std::vector or compatible type containing dlib::matrix
27               objects, each representing a column vector of the same size.
28             - for all valid i, j:
29                 - is_col_vector(v[i]) == true
30                 - v[i].size() > 0
31                 - v[i].size() == v[j].size()
32                 - i.e. v contains only column vectors and all the column vectors
33                   have the same non-zero length
34             - rand_type == a type that implements the dlib/rand/rand_kernel_abstract.h interface
35         ensures
36             - returns a hash function H such that:
37                 - H.num_hash_bins() == pow(2,bits)
38                 - H will be setup so that it hashes the contents of v such that each bin
39                   ends up with roughly the same number of elements in it.  This is
40                   accomplished by picking random hyperplanes passing though the data.  In
41                   particular, each plane normal vector is filled with Gaussian random
42                   numbers and we also perform basic centering to ensure the plane passes
43                   though the data.
44             - This function uses the supplied random number generator, rnd, to drive part
45               of its processing.  Therefore, giving different random number generators
46               will produce different outputs.
47     !*/
48 
49 // ----------------------------------------------------------------------------------------
50 
51     template <
52         typename vector_type
53         >
54     projection_hash create_random_projection_hash (
55         const vector_type& v,
56         const int bits
57     );
58     /*!
59         requires
60             - 0 < bits <= 32
61             - v.size() > 1
62             - vector_type == a std::vector or compatible type containing dlib::matrix
63               objects, each representing a column vector of the same size.
64             - for all valid i, j:
65                 - is_col_vector(v[i]) == true
66                 - v[i].size() > 0
67                 - v[i].size() == v[j].size()
68                 - i.e. v contains only column vectors and all the column vectors
69                   have the same non-zero length
70         ensures
71             - returns create_random_projection_hash(v,bits,dlib::rand())
72               (i.e. calls the above function with a default initialized random number generator)
73     !*/
74 
75 // ----------------------------------------------------------------------------------------
76 
77     template <
78         typename vector_type
79         >
80     projection_hash create_max_margin_projection_hash (
81         const vector_type& v,
82         const int bits,
83         const double C,
84         dlib::rand& rnd
85     );
86     /*!
87         requires
88             - 0 < bits <= 32
89             - v.size() > 1
90             - vector_type == a std::vector or compatible type containing dlib::matrix
91               objects, each representing a column vector of the same size.
92             - for all valid i, j:
93                 - is_col_vector(v[i]) == true
94                 - v[i].size() > 0
95                 - v[i].size() == v[j].size()
96                 - i.e. v contains only column vectors and all the column vectors
97                   have the same non-zero length
98             - rand_type == a type that implements the dlib/rand/rand_kernel_abstract.h interface
99         ensures
100             - returns a hash function H such that:
101                 - H.num_hash_bins() == pow(2,bits)
102                 - H will be setup so that it hashes the contents of v such that
103                   each bin ends up with roughly the same number of elements
104                   in it.  This is accomplished using a variation on the random hyperplane
105                   generation technique from the paper:
106                     Random Maximum Margin Hashing by Alexis Joly and Olivier Buisson
107                   In particular, we use the svm_c_linear_dcd_trainer to generate planes.
108                   We train it on randomly selected and randomly labeled points from v.
109                   The C SVM parameter is set to the given C argument.
110             - This function uses the supplied random number generator, rnd, to drive part
111               of its processing.  Therefore, giving different random number generators
112               will produce different outputs.
113     !*/
114 
115 // ----------------------------------------------------------------------------------------
116 
117     template <
118         typename vector_type
119         >
120     projection_hash create_max_margin_projection_hash (
121         const vector_type& v,
122         const int bits,
123         const double C = 10
124     );
125     /*!
126         requires
127             - 0 < bits <= 32
128             - v.size() > 1
129             - vector_type == a std::vector or compatible type containing dlib::matrix
130               objects, each representing a column vector of the same size.
131             - for all valid i, j:
132                 - is_col_vector(v[i]) == true
133                 - v[i].size() > 0
134                 - v[i].size() == v[j].size()
135                 - i.e. v contains only column vectors and all the column vectors
136                   have the same non-zero length
137         ensures
138             - returns create_max_margin_projection_hash(v,bits,C,dlib::rand())
139               (i.e. calls the above function with a default initialized random number generator)
140     !*/
141 
142 // ----------------------------------------------------------------------------------------
143 
144 }
145 
146 #endif // DLIB_CREATE_RANDOM_PROJECTION_HAsH_ABSTRACT_Hh_
147 
148 
149