GRNN Neural Network Class – library MetaTrader 5

The CNetGRNN class realizes a generalized regression neural network (General Regression Neural Network – GRNN).

Creation of the network is declared to be the class parametric constructor.

CNetGRNN *net=new CNetGRNN(input vector size, output vector size);

Learning network is provided by calling the Learn method (the number of learning patterns, input data array, output data array, the number of learning cycles, the maximum learning error).

Input and output learning data are located in one-dimensional arrays vector by vector. The learning process is limited either by the number of learning epochs or admissible error.

The Learn method returns the following values:

  • 0 – network learning is completed and learning result can be checked through the class variable: mse – learning error, epoch – number of accomplished learning cycles;
  • -4 – not enough memory. 

The Calculate method (input vector array, network response array) is used to get response network.

Save (open file handle with FILE_WRITE and FILE_BIN flags) and Load (open file handle with FILE_READ and FILE_BIN flags) methods are intended for saving the network to a file and loading the network from the file respectively. Network topology, learning errors and array weights are saved to the file. If parameters of the loaded network topology differ from the parameters of the established network topology, the network will not be loaded and the Load method will return false.

Alternative:  MA_2HTF - indicator MetaTrader 5

Using of the class is shown in the attached specimens: Test_GRNN_XOR – learning network function “excluding OR”, Test_GRNN_MUL_ADD – learning network multiplication and addition of integers.


📈 ROBOTFX MetaTrader Expert Advisors and Indicators to maximize profits and minimize the risks