Neuron Net
Macros | Functions
Convolution layer's neuron Feed Forward

Describes the feed forward process for the Neuron of convolution layer. More...

Macros

#define def_k_FeedForwardConv   7
 Index of the kernel of the convolution neuron for Feed forward process (FeedForwardConv) More...
 
#define def_k_ffc_matrix_w   0
 Weights matrix (m+1)*n, where m - input window and n - output window. More...
 
#define def_k_ffc_matrix_i   1
 Inputs tesor. More...
 
#define def_k_ffc_matrix_o   2
 Output tensor. More...
 
#define def_k_ffc_inputs   3
 Number of inputs. More...
 
#define def_k_ffc_step   4
 Step size. More...
 
#define def_k_ffc_window_in   5
 Size of input window. More...
 
#define def_k_ffс_window_out   6
 Size of output window. More...
 
#define def_k_ffc_activation   7
 Activation type (ENUM_ACTIVATION) More...
 

Functions

__kernel void FeedForwardConv (__global double *matrix_w, __global double *matrix_i, __global double *matrix_o, int inputs, int step, int window_in, int window_out, uint activation)
 Kernel of the Convolution neuron for Feed forward process (CNeuronConvOCL) More...
 

Detailed Description

Describes the feed forward process for the Neuron of convolution layer.

Macro Definition Documentation

◆ def_k_FeedForwardConv

#define def_k_FeedForwardConv   7

Index of the kernel of the convolution neuron for Feed forward process (FeedForwardConv)

Definition at line 176 of file NeuroNet.mqh.

◆ def_k_ffc_activation

#define def_k_ffc_activation   7

Activation type (ENUM_ACTIVATION)

Definition at line 184 of file NeuroNet.mqh.

◆ def_k_ffc_inputs

#define def_k_ffc_inputs   3

Number of inputs.

Definition at line 180 of file NeuroNet.mqh.

◆ def_k_ffc_matrix_i

#define def_k_ffc_matrix_i   1

Inputs tesor.

Definition at line 178 of file NeuroNet.mqh.

◆ def_k_ffc_matrix_o

#define def_k_ffc_matrix_o   2

Output tensor.

Definition at line 179 of file NeuroNet.mqh.

◆ def_k_ffc_matrix_w

#define def_k_ffc_matrix_w   0

Weights matrix (m+1)*n, where m - input window and n - output window.

Definition at line 177 of file NeuroNet.mqh.

◆ def_k_ffc_step

#define def_k_ffc_step   4

Step size.

Definition at line 181 of file NeuroNet.mqh.

◆ def_k_ffc_window_in

#define def_k_ffc_window_in   5

Size of input window.

Definition at line 182 of file NeuroNet.mqh.

◆ def_k_ffс_window_out

#define def_k_ffс_window_out   6

Size of output window.

Definition at line 183 of file NeuroNet.mqh.

Function Documentation

◆ FeedForwardConv()

__kernel void FeedForwardConv ( __global double *  matrix_w,
__global double *  matrix_i,
__global double *  matrix_o,
int  inputs,
int  step,
int  window_in,
int  window_out,
uint  activation 
)

Kernel of the Convolution neuron for Feed forward process (CNeuronConvOCL)

Parameters
[in]matrix_wWeights matrix (m+1)*n, where m - input window and n - output window
[in]matrix_iInputs tesor
[out]matrix_oOutput tensor
inputsNumber of inputs
stepStep size
window_inSize of input window
window_outSize of output window
activationActivation type (ENUM_ACTIVATION)

Definition at line 325 of file NeuroNet.cl.

334  {
335  int i=get_global_id(0);
336  int w_in=window_in;
337  int w_out=window_out;
338  double sum=0.0;
339  double4 inp, weight;
340  int shift_out=w_out*i;
341  int shift_in=step*i;
342  for(int out=0;out<w_out;out++)
343  {
344  int shift=(w_in+1)*out;
345  int stop=(w_in<=(inputs-shift_in) ? w_in : (inputs-shift_in));
346  for(int k=0; k<=stop; k=k+4)
347  {
348  switch(stop-k)
349  {
350  case 0:
351  inp=(double4)(1,0,0,0);
352  weight=(double4)(matrix_w[shift+k],0,0,0);
353  break;
354  case 1:
355  inp=(double4)(matrix_i[shift_in+k],1,0,0);
356  weight=(double4)(matrix_w[shift+k],matrix_w[shift+k+1],0,0);
357  break;
358  case 2:
359  inp=(double4)(matrix_i[shift_in+k],matrix_i[shift_in+k+1],1,0);
360  weight=(double4)(matrix_w[shift+k],matrix_w[shift+k+1],matrix_w[shift+k+2],0);
361  break;
362  case 3:
363  inp=(double4)(matrix_i[shift_in+k],matrix_i[shift_in+k+1],matrix_i[shift_in+k+2],1);
364  weight=(double4)(matrix_w[shift+k],matrix_w[shift+k+1],matrix_w[shift+k+2],matrix_w[shift+k+3]);
365  break;
366  default:
367  inp=(double4)(matrix_i[shift_in+k],matrix_i[shift_in+k+1],matrix_i[shift_in+k+2],matrix_i[shift_in+k+3]);
368  weight=(double4)(matrix_w[shift+k],matrix_w[shift+k+1],matrix_w[shift+k+2],matrix_w[shift+k+3]);
369  break;
370  }
371  sum+=dot(inp,weight);
372  }
373  switch(activation)
374  {
375  case 0:
376  sum=tanh(sum);
377  break;
378  case 1:
379  sum=1/(1+exp(-clamp(sum,-50.0,50.0)));
380  break;
381  case 2:
382  if(sum<0)
383  sum*=0.01;
384  break;
385  default:
386  break;
387  }
388  matrix_o[out+shift_out]=sum;
389  }
390  }