SHOGUN  3.2.1
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
ConvolutionalFeatureMap.h
浏览该文件的文档.
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>
38 
39 namespace shogun
40 {
41 
46 {
49 
52 
55 };
56 
57 template <class T> class SGVector;
58 template <class T> class SGMatrix;
59 class CDynamicObjectArray;
60 
65 {
66 public:
87  CConvolutionalFeatureMap(int32_t input_width, int32_t input_height,
88  int32_t radius_x, int32_t radius_y,
89  int32_t stride_x=1, int32_t stride_y=1,
90  int32_t index=0,
92 
109  void compute_activations(SGVector<float64_t> parameters,
110  CDynamicObjectArray* layers,
111  SGVector<int32_t> input_indices,
112  SGMatrix<float64_t> activations,
113  SGMatrix<float64_t> buffer);
114 
135  void compute_gradients(SGVector<float64_t> parameters,
136  SGMatrix<float64_t> activations,
137  SGMatrix<float64_t> activation_gradients,
138  CDynamicObjectArray* layers,
139  SGVector<int32_t> input_indices,
140  SGVector<float64_t> parameter_gradients);
141 
155  void pool_activations(SGMatrix<float64_t> activations,
156  int32_t pooling_width,
157  int32_t pooling_height,
158  SGMatrix<float64_t> pooled_activations,
159  SGMatrix<float64_t> max_indices);
160 
161 protected:
181  void convolve(SGMatrix<float64_t> inputs,
182  SGMatrix<float64_t> weights,
183  SGMatrix<float64_t> outputs,
184  bool flip,
185  bool reset_output,
186  int32_t inputs_row_offset,
187  int32_t outputs_row_offset);
188 
205  SGMatrix<float64_t> local_gradients,
206  SGMatrix<float64_t> weight_gradients,
207  int32_t inputs_row_offset,
208  int32_t local_gradients_row_offset);
209 
210 protected:
212  int32_t m_input_width;
213 
215  int32_t m_input_height;
216 
218  int32_t m_radius_x;
219 
221  int32_t m_radius_y;
222 
224  int32_t m_stride_x;
225 
227  int32_t m_stride_y;
228 
232  int32_t m_index;
233 
236 
238  int32_t m_output_width;
239 
242 
245 
248 
250  int32_t m_row_offset;
251 
253  int32_t m_filter_width;
254 
257 };
258 
259 }
260 #endif
void convolve(SGMatrix< float64_t > inputs, SGMatrix< float64_t > weights, SGMatrix< float64_t > outputs, bool flip, bool reset_output, int32_t inputs_row_offset, int32_t outputs_row_offset)
void compute_activations(SGVector< float64_t > parameters, CDynamicObjectArray *layers, SGVector< int32_t > input_indices, SGMatrix< float64_t > activations, SGMatrix< float64_t > buffer)
EConvMapActivationFunction m_activation_function
Handles convolution and gradient calculation for a single feature map in a convolutional neural netwo...
CConvolutionalFeatureMap(int32_t input_width, int32_t input_height, int32_t radius_x, int32_t radius_y, int32_t stride_x=1, int32_t stride_y=1, int32_t index=0, EConvMapActivationFunction function=CMAF_IDENTITY)
Dynamic array class for CSGObject pointers that creates an array that can be used like a list or an a...
EConvMapActivationFunction
Determines the activation function for neurons in a convolutional feature map.
void compute_gradients(SGVector< float64_t > parameters, SGMatrix< float64_t > activations, SGMatrix< float64_t > activation_gradients, CDynamicObjectArray *layers, SGVector< int32_t > input_indices, SGVector< float64_t > parameter_gradients)
void compute_weight_gradients(SGMatrix< float64_t > inputs, SGMatrix< float64_t > local_gradients, SGMatrix< float64_t > weight_gradients, int32_t inputs_row_offset, int32_t local_gradients_row_offset)
void pool_activations(SGMatrix< float64_t > activations, int32_t pooling_width, int32_t pooling_height, SGMatrix< float64_t > pooled_activations, SGMatrix< float64_t > max_indices)

SHOGUN 机器学习工具包 - 项目文档