Neuron Net
Macros | Functions
Gradients Calculation kernels

Describes the process of gradients calculation for the Neuron Base. More...

Macros

#define def_k_CalcOutputGradient   1
 Index of Output gradients calculation kernel (CalcOutputGradient) More...
 
#define def_k_cog_matrix_t   0
 Target tensor. More...
 
#define def_k_cog_matrix_o   1
 Output tensor. More...
 
#define def_k_cog_matrix_ig   2
 Tensor of gradients at previous layer. More...
 
#define def_k_cog_activation   3
 Activation type (ENUM_ACTIVATION) More...
 
#define def_k_CalcHiddenGradient   2
 Index of Hidden gradients calculation kernel (CalcHiddenGradient) More...
 
#define def_k_chg_matrix_w   0
 Weights matrix (m+1)*n, where m - number of neurons in previous layer and n - number of neurons in current layer. More...
 
#define def_k_chg_matrix_g   1
 Tensor of gradients at current layer. More...
 
#define def_k_chg_matrix_o   2
 Output tensor. More...
 
#define def_k_chg_matrix_ig   3
 Tensor of gradients at previous layer. More...
 
#define def_k_chg_outputs   4
 Number of outputs. More...
 
#define def_k_chg_activation   5
 Activation type (ENUM_ACTIVATION) More...
 

Functions

__kernel void CalcOutputGradient (__global double *matrix_t, __global double *matrix_o, __global double *matrix_ig, int activation)
 Describes the process of output gradients calculation for the Neuron Base (CNeuronBaseOCL). More...
 
__kernel void CalcHiddenGradient (__global double *matrix_w, __global double *matrix_g, __global double *matrix_o, __global double *matrix_ig, int outputs, int activation)
 Describes the process of hidden gradients calculation for the Neuron Base (CNeuronBaseOCL). More...
 
virtual bool CNeuronBaseOCL::UpdateInputWeights (CObject *SourceObject)
 Dispatch method for defining the subroutine for updating weights. More...
 
virtual bool CNeuronBaseOCL::calcHiddenGradients (CNeuronBaseOCL *NeuronOCL)
 Method to transfer gradient to previous layer by calling kernel CalcHiddenGradient(). More...
 
virtual bool CNeuronBaseOCL::calcOutputGradients (CArrayDouble *Target)
 Method of output gradients calculation by calling kernel CalcOutputGradient(). More...
 

Detailed Description

Describes the process of gradients calculation for the Neuron Base.

Detailed description on the link.

Macro Definition Documentation

◆ def_k_CalcHiddenGradient

#define def_k_CalcHiddenGradient   2

Index of Hidden gradients calculation kernel (CalcHiddenGradient)

Definition at line 107 of file NeuroNet.mqh.

◆ def_k_CalcOutputGradient

#define def_k_CalcOutputGradient   1

Index of Output gradients calculation kernel (CalcOutputGradient)

Definition at line 101 of file NeuroNet.mqh.

◆ def_k_chg_activation

#define def_k_chg_activation   5

Activation type (ENUM_ACTIVATION)

Definition at line 113 of file NeuroNet.mqh.

◆ def_k_chg_matrix_g

#define def_k_chg_matrix_g   1

Tensor of gradients at current layer.

Definition at line 109 of file NeuroNet.mqh.

◆ def_k_chg_matrix_ig

#define def_k_chg_matrix_ig   3

Tensor of gradients at previous layer.

Definition at line 111 of file NeuroNet.mqh.

◆ def_k_chg_matrix_o

#define def_k_chg_matrix_o   2

Output tensor.

Definition at line 110 of file NeuroNet.mqh.

◆ def_k_chg_matrix_w

#define def_k_chg_matrix_w   0

Weights matrix (m+1)*n, where m - number of neurons in previous layer and n - number of neurons in current layer.

Definition at line 108 of file NeuroNet.mqh.

◆ def_k_chg_outputs

#define def_k_chg_outputs   4

Number of outputs.

Definition at line 112 of file NeuroNet.mqh.

◆ def_k_cog_activation

#define def_k_cog_activation   3

Activation type (ENUM_ACTIVATION)

Definition at line 105 of file NeuroNet.mqh.

◆ def_k_cog_matrix_ig

#define def_k_cog_matrix_ig   2

Tensor of gradients at previous layer.

Definition at line 104 of file NeuroNet.mqh.

◆ def_k_cog_matrix_o

#define def_k_cog_matrix_o   1

Output tensor.

Definition at line 103 of file NeuroNet.mqh.

◆ def_k_cog_matrix_t

#define def_k_cog_matrix_t   0

Target tensor.

Definition at line 102 of file NeuroNet.mqh.

Function Documentation

◆ CalcHiddenGradient()

__kernel void CalcHiddenGradient ( __global double *  matrix_w,
__global double *  matrix_g,
__global double *  matrix_o,
__global double *  matrix_ig,
int  outputs,
int  activation 
)

Describes the process of hidden gradients calculation for the Neuron Base (CNeuronBaseOCL).

Detailed description on the link.

Parameters
[in]matrix_wWeights matrix (m+1)*n, where m - number of neurons in previous layer and n - number of neurons in current layer
[in]matrix_gTensor of gradients at current layer
[in]matrix_oPrevious layer Output tensor
[out]matrix_igTensor of gradients at previous layer
outputsNumber of outputs
activationActivation type (ENUM_ACTIVATION)

Definition at line 108 of file NeuroNet.cl.

115  {
116  int i=get_global_id(0);
117  int inputs=get_global_size(0);
118  double sum=0;
119  double out=matrix_o[i];
120  double4 grad, weight;
121  for(int k=0;k<outputs;k+=4)
122  {
123  switch(outputs-k)
124  {
125  case 1:
126  grad=(double4)(matrix_g[k],0,0,0);
127  weight=(double4)(matrix_w[k*inputs+i],0,0,0);
128  break;
129  case 2:
130  grad=(double4)(matrix_g[k],matrix_g[k+1],0,0);
131  weight=(double4)(matrix_w[k*inputs+i],matrix_w[k*inputs+i+1],0,0);
132  break;
133  case 3:
134  grad=(double4)(matrix_g[k],matrix_g[k+1],matrix_g[k+2],0);
135  weight=(double4)(matrix_w[k*inputs+i],matrix_w[k*inputs+i+1],matrix_w[k*inputs+i+2],0);
136  break;
137  default:
138  grad=(double4)(matrix_g[k],matrix_g[k+1],matrix_g[k+2],matrix_g[k+3]);
139  weight=(double4)(matrix_w[k*inputs+i],matrix_w[k*inputs+i+1],matrix_w[k*inputs+i+2],matrix_w[k*inputs+i+3]);
140  break;
141  }
142  sum+=dot(grad,weight);
143  }
144  switch(activation)
145  {
146  case 0:
147  sum=clamp(sum+out,-1.0,1.0)-out;
148  sum=sum*(1-pow(out==1 || out==-1 ? 0.99999999 : out,2));
149  break;
150  case 1:
151  sum=clamp(sum+out,0.0,1.0)-out;
152  sum=sum*(out==0 || out==1 ? 0.00000001 : (out*(1-out)));
153  break;
154  case 2:
155  if(out<0)
156  sum*=0.01;
157  break;
158  default:
159  break;
160  }
161  matrix_ig[i]=sum;
162  }

◆ calcHiddenGradients()

bool CNeuronBaseOCL::calcHiddenGradients ( CNeuronBaseOCL NeuronOCL)
virtual

Method to transfer gradient to previous layer by calling kernel CalcHiddenGradient().

Parameters
NeuronOCLPointer to next layer.

Definition at line 3204 of file NeuroNet.mqh.

◆ CalcOutputGradient()

__kernel void CalcOutputGradient ( __global double *  matrix_t,
__global double *  matrix_o,
__global double *  matrix_ig,
int  activation 
)

Describes the process of output gradients calculation for the Neuron Base (CNeuronBaseOCL).

Detailed description on the link.

Parameters
[in]matrix_tTarget tensor
[in]matrix_oOutput tensor
[out]matrix_igTensor of gradients
activationActivation type (ENUM_ACTIVATION)

Definition at line 75 of file NeuroNet.cl.

80  {
81  int i=get_global_id(0);
82  double temp=0;
83  double out=matrix_o[i];
84  switch(activation)
85  {
86  case 0:
87  temp=clamp(matrix_t[i],-1.0,1.0)-out;
88  temp=temp*(1-pow(out==1 || out==-1 ? 0.99999999 : out,2));
89  break;
90  case 1:
91  temp=clamp(matrix_t[i],0.0,1.0)-out;
92  temp=temp*(out==0 || out==1 ? 0.00000001 : (out*(1-out)));
93  break;
94  case 2:
95  temp=(matrix_t[i]-out)*(out>=0 ? 1.0 : 0.01);
96  break;
97  default:
98  temp=(matrix_t[i]-out);
99  break;
100  }
101  matrix_ig[i]=temp;
102  }

◆ calcOutputGradients()

bool CNeuronBaseOCL::calcOutputGradients ( CArrayDouble *  Target)
virtual

Method of output gradients calculation by calling kernel CalcOutputGradient().

Parameters
TargetTraget value

Definition at line 3237 of file NeuroNet.mqh.

◆ UpdateInputWeights()

bool CNeuronBaseOCL::UpdateInputWeights ( CObject *  SourceObject)
virtual

Dispatch method for defining the subroutine for updating weights.

Parameters
SourceObjectPointer to previos layer.

Definition at line 3359 of file NeuroNet.mqh.