Neuron Net
Macros | Functions
Feed Forward proccess kernel

Describes the forward path process for the Neuron Base. More...

Macros

#define def_k_FeedForward   0
 Index of FeedForward kernel. More...
 
#define def_k_ff_matrix_w   0
 Weights matrix (m+1)*n, where m - number of neurons in layer and n - number of outputs (neurons in next layer) More...
 
#define def_k_ff_matrix_i   1
 Inputs tesor. More...
 
#define def_k_ff_matrix_o   2
 Output tensor. More...
 
#define def_k_ff_inputs   3
 Number of inputs. More...
 
#define def_k_ff_activation   4
 Activation type (ENUM_ACTIVATION) More...
 

Functions

__kernel void FeedForward (__global double *matrix_w, __global double *matrix_i, __global double *matrix_o, int inputs, int activation)
 Describes the forward path process for the Neuron Base (CNeuronBaseOCL). More...
 
virtual bool CNeuronBaseOCL::feedForward (CNeuronBaseOCL *NeuronOCL)
 Feed Forward method of calling kernel FeedForward(). More...
 

Detailed Description

Describes the forward path process for the Neuron Base.

Detailed description on the link.

Macro Definition Documentation

◆ def_k_FeedForward

#define def_k_FeedForward   0

Index of FeedForward kernel.

Definition at line 90 of file NeuroNet.mqh.

◆ def_k_ff_activation

#define def_k_ff_activation   4

Activation type (ENUM_ACTIVATION)

Definition at line 95 of file NeuroNet.mqh.

◆ def_k_ff_inputs

#define def_k_ff_inputs   3

Number of inputs.

Definition at line 94 of file NeuroNet.mqh.

◆ def_k_ff_matrix_i

#define def_k_ff_matrix_i   1

Inputs tesor.

Definition at line 92 of file NeuroNet.mqh.

◆ def_k_ff_matrix_o

#define def_k_ff_matrix_o   2

Output tensor.

Definition at line 93 of file NeuroNet.mqh.

◆ def_k_ff_matrix_w

#define def_k_ff_matrix_w   0

Weights matrix (m+1)*n, where m - number of neurons in layer and n - number of outputs (neurons in next layer)

Definition at line 91 of file NeuroNet.mqh.

Function Documentation

◆ FeedForward()

__kernel void FeedForward ( __global double *  matrix_w,
__global double *  matrix_i,
__global double *  matrix_o,
int  inputs,
int  activation 
)

Describes the forward path process for the Neuron Base (CNeuronBaseOCL).

Detailed description on the link.

Parameters
[in]matrix_wWeights matrix (m+1)*n, where m - number of neurons in layer and n - number of outputs (neurons in next layer)
[in]matrix_iInputs tesor
[out]matrix_oOutput tensor
inputsNumber of inputs
activationActivation type (ENUM_ACTIVATION)

Definition at line 15 of file NeuroNet.cl.

21  {
22  int i=get_global_id(0);
23  double sum=0.0;
24  double4 inp, weight;
25  int shift=(inputs+1)*i;
26  for(int k=0; k<=inputs; k=k+4)
27  {
28  switch(inputs-k)
29  {
30  case 0:
31  inp=(double4)(1,0,0,0);
32  weight=(double4)(matrix_w[shift+k],0,0,0);
33  break;
34  case 1:
35  inp=(double4)(matrix_i[k],1,0,0);
36  weight=(double4)(matrix_w[shift+k],matrix_w[shift+k+1],0,0);
37  break;
38  case 2:
39  inp=(double4)(matrix_i[k],matrix_i[k+1],1,0);
40  weight=(double4)(matrix_w[shift+k],matrix_w[shift+k+1],matrix_w[shift+k+2],0);
41  break;
42  case 3:
43  inp=(double4)(matrix_i[k],matrix_i[k+1],matrix_i[k+2],1);
44  weight=(double4)(matrix_w[shift+k],matrix_w[shift+k+1],matrix_w[shift+k+2],matrix_w[shift+k+3]);
45  break;
46  default:
47  inp=(double4)(matrix_i[k],matrix_i[k+1],matrix_i[k+2],matrix_i[k+3]);
48  weight=(double4)(matrix_w[shift+k],matrix_w[shift+k+1],matrix_w[shift+k+2],matrix_w[shift+k+3]);
49  break;
50  }
51  sum+=dot(inp,weight);
52  }
53  switch(activation)
54  {
55  case 0:
56  sum=tanh(sum);
57  break;
58  case 1:
59  sum=1/(1+exp(-clamp(sum,-50.0,50.0)));
60  break;
61  case 2:
62  if(sum<0)
63  sum*=0.01;
64  break;
65  default:
66  break;
67  }
68  matrix_o[i]=sum;
69  }

◆ feedForward()

bool CNeuronBaseOCL::feedForward ( CNeuronBaseOCL NeuronOCL)
protectedvirtual

Feed Forward method of calling kernel FeedForward().

Parameters
NeuronOCLPointer to previos layer.

Reimplemented in CNeuronAttentionOCL, CNeuronConvOCL, and CNeuronProofOCL.

Definition at line 3172 of file NeuroNet.mqh.