SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ConvolutionalFeatureMap.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014, Shogun Toolbox Foundation
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7 
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its
16  * contributors may be used to endorse or promote products derived from this
17  * software without specific prior written permission.
18 
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  *
31  * Written (W) 2014 Khaled Nasr
32  */
33 
34 #ifndef __CONVOLUTIONALFEATUREMAP_H__
35 #define __CONVOLUTIONALFEATUREMAP_H__
36 
37 #include <shogun/lib/common.h>
39 
40 namespace shogun
41 {
42 
47 {
50 
53 
56 };
57 
58 template <class T> class SGVector;
59 template <class T> class SGMatrix;
60 class CDynamicObjectArray;
61 
66 {
67 public:
88  CConvolutionalFeatureMap(int32_t input_width, int32_t input_height,
89  int32_t radius_x, int32_t radius_y,
90  int32_t stride_x=1, int32_t stride_y=1,
91  int32_t index=0,
93  ENLAutoencoderPosition autoencoder_position = NLAP_NONE);
94 
108  void compute_activations(SGVector<float64_t> parameters,
109  CDynamicObjectArray* layers,
110  SGVector<int32_t> input_indices,
111  SGMatrix<float64_t> activations);
112 
133  void compute_gradients(SGVector<float64_t> parameters,
134  SGMatrix<float64_t> activations,
135  SGMatrix<float64_t> activation_gradients,
136  CDynamicObjectArray* layers,
137  SGVector<int32_t> input_indices,
138  SGVector<float64_t> parameter_gradients);
139 
153  void pool_activations(SGMatrix<float64_t> activations,
154  int32_t pooling_width,
155  int32_t pooling_height,
156  SGMatrix<float64_t> pooled_activations,
157  SGMatrix<float64_t> max_indices);
158 
159 protected:
179  void convolve(SGMatrix<float64_t> inputs,
180  SGMatrix<float64_t> weights,
181  SGMatrix<float64_t> outputs,
182  bool flip,
183  bool reset_output,
184  int32_t inputs_row_offset,
185  int32_t outputs_row_offset);
186 
203  SGMatrix<float64_t> local_gradients,
204  SGMatrix<float64_t> weight_gradients,
205  int32_t inputs_row_offset,
206  int32_t local_gradients_row_offset);
207 
208 protected:
210  int32_t m_input_width;
211 
213  int32_t m_input_height;
214 
216  int32_t m_radius_x;
217 
219  int32_t m_radius_y;
220 
222  int32_t m_stride_x;
223 
225  int32_t m_stride_y;
226 
230  int32_t m_index;
231 
234 
236  int32_t m_output_width;
237 
240 
243 
246 
248  int32_t m_row_offset;
249 
251  int32_t m_filter_width;
252 
255 
260 };
261 
262 }
263 #endif

SHOGUN Machine Learning Toolbox - Documentation