MLP Neural Network Class - MetaTrader 5 Library | MT5 EA Download - MetaTrader 5 Resources
CNetMLP provides multi-layer perceptron (MLP).
The characteristic of this class is that the input vector and network structure concepts are separated, that is, the input vector and network structure description are not related to each other.
The size of the input vector can be any value within a reasonable range. The input data should be normalized, i.e. the data should be in the range -1..1 or 0..1. Depending on the type of data used, various activation functions are applied to the network: hyperbolic tangent is applied to the -1..1 data range, while sigmoid is applied to the 0..1 data range.
The network adopts a layer-by-layer structure and signals are transmitted directly. The network structure is described by a one-dimensional array, where the value of the array element determines the number of neurons in the corresponding layer. The number of layers and neurons is not limited. The network can be composed of individual neurons.
Each neuron has multiple inputs (defined by its position in the network) and an output. If you need the network to give N responses, then the last layer should contain N neurons. The learning algorithm is iRprop. The input and output training data are located vector by vector in a one-dimensional array. The learning process is limited by the number of learning epochs or the allowed error.
The creation of the network is declared as a class parameter constructor.
CNetMLP *net= new CNetMLP(
Number of layers, array of network structures, input vector size, activation function type: 0 - sigmoid, 1 - hyperbolic tangent).
Provide online teaching by calling the Learn method (number of teaching modes, input data array, output data array, number of learning cycles, allowed learning error). Teaching results can be checked through class variables: mse – learning error and epoch – number of completed learning cycles.
The calculation method (array of input vectors, array of network responses) is used to obtain the network response.
The Save (open a file handle with the FILE_WRITE and FILE_BIN flags) and Load (open a file handle with the FILE_READ and FILE_BIN flags) methods are used to save a network to a file and load a network from a file respectively. Save only the learning error and weight arrays to file. The created and downloaded network must be verified for compliance before using the Load method (handle).
The use of this class is shown in the attached sample. Class and sample files must be placed in one folder.
Attachment download
📎 class_netmlp.mqh (12.74 KB)
📎 testmlps.mq5 (4.67 KB)
Source: MQL5 #596
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •