Complete and most importantly beautiful.
Such a question to Eugene - did you copy the same class (with minor changes) into all SOM_exN files?
and the second question - did I understand correctly that you have the functions of map display and map calculations in one class?
Such a question to Eugene - did you copy the same class (with minor changes) into all SOM_exN files ?
and the second question - did I understand correctly that you have the functions of map display and map calculations in one class?
Yes, you are right, the class is the same. Minor changes are caused by the specifics of solved tasks (data dimensionality and RGB,CMYK display methods). Map display functions and calculations are combined into one class.
The general structure is as follows:
//--- load the training set into the array m_training_sets_array[] KohonenMap.LoadData() //--- network training - modification of node weights m_som_nodes[] KohonenMap.Train(); //--- forming a picture with a map - "projecting" the state of nodes into an instance of the cIntBMP class KohonenMap.Render(); //--- show the captions on the map for each of the elements of the training set //i.e. add to the figure the identifiers of each element of the training set KohonenMap.ShowTrainPatterns(); //--- show the picture on the graph KohonenMap.ShowBMP();
calculation is done in the Train method (for some cases Render and ShowBMP are called inside it to show the training process), then the results are "transferred" to a bmp picture which is displayed in the ShowBMP method.
The cIntBMP class was used for rendering and displaying.
Yes, you are right, the class is the same. Minor changes are due to the specifics of the tasks to be solved (data dimensionality and RGB,CMYK display methods ). Map display functions and calculations are combined into one class.
Maybe then for convenience of working with classes we should change it into a hierarchy? I'm sure it will reduce the code and make it easier to get acquainted with it.
especially when it comes to the same functions identical in all files.
Maybe for convenience of working with classes we should change it into a hierarchy? I'm sure it will reduce the code and make it easier to get acquainted with it.
especially when it comes to the same functions being the same in all files.
The idea was to show practical aspects of using Kohonen networks.
Methodologically it turned out to be more convenient to consider all tasks separately. there is a small hierarchy, CSOM->CSomWeb, CSOM->CSomFood (all of them three-dimensional, like the first example). In the 4-dimensional case of Fisher 's irises, along with CSOM, CSomNode also had to be changed to handle the 4 components. Then component planes appeared and m_bmp became an array.
Then, after refusing to display fixed specific 3-dimensional (RGB) and 4-dimensional (CMYK) data, we got SOM.mq5, which allows you to work with data of any dimension, the data of previous examples were transferred to files of a certain format, and their analysis is further carried out in the language of component planes.
In essence, we need som.mq5 as a tool, and all the other examples are of a tutorial nature and are just illustrations of the features of Kohonen networks.
in the CSOM::ReadCSVData function
string is incorrect
// network initialisation, 10000 iterations, grid of CellsX*CellsY nodes, image ImageXSize x ImageYSize int dimension=ArraySize(stringsarr)-1; KohonenMap.InitParameters(dimension,10000,CellsX,CellsY,ImageXSize,ImageYSize);
in the CSOM::ReadCSVData function
string is wrong
If you mean string:
int dimension=ArraySize(stringsarr)-1;
it is the specifics of the input data file format - the dimension is assumed to be equal to the number of columns-1.
The last column is the string name of the training sample. For example, in products.csv
Protein;Carbohydrate;Fat;Title 0.4;11.8;0.1;Apples
the first line-header, containing the names of components, they will go to the array m_som_titles[].
then the data (in m_training_sets_array[]) and titles (in m_train_titles[]) follow.
KohonenMap
you have an object of this class in the class itself. Here.
-------------------------
In this regard, from the point of view of further use of the CSOM class standalone it is necessary:
1. Separate files with CSOMNode, CSOM classes and specific scripts of their use
2. Remove external input parameters from the CSOM class to a specific script.
3. Add all these parameters in the class itself
public: ColorSchemes m_clrSchema; // gradient scheme int m_maxpict; // number of pictures in a row bool m_bHexCell; // hexagonal cells bool m_bShowBorder; // show boundaries bool m_bShowTitle; // show captions
4. In this regard, expand the CSOM::Init function by 5 parameters for initialisation (you can remove m_dimension, which is set in ReadCSVData)
Init(int iter, int xc, int yc, int bmpw, int bmph, int maxpic, ColorSchemes clrSchema, bool bhex, bool bborder, bool btitle)
This will allow you to take the CSOM class out of the Expert Advisor file and use it simply as an include to the necessary projects
#property script_show_inputs #include "SOM.mqh" input string DataFileName="products.csv"; // Data file name input int CellsX=30; // Number of nodes by X input int CellsY=30; // Number of nodes in Y input int ImageW=250; // Picture width input int ImageH=250; // Picture height input int MaxPictures=4; // max. pictures per line input bool HexagonalCell=true; // Hexagonal cells input bool ShowBorders=false; // show cell borders input bool ShowTitles=true; // display names in coordinate planes input ColorSchemes ColorScheme=Blue_Green_Red; // Gradient colours //------------------------------------------------------------------ OnStart void OnStart() { CSOM KohonenMap; MathSrand(200); // load the training set from the file if(!KohonenMap.LoadTrainDataFromFile(DataFileName)) { Print("Error loading data for training"); return; } KohonenMap.Init(10000, CellsX, CellsY, ImageW, ImageH, MaxPictures, ColorScheme, HexagonalCell, ShowBorders, ShowTitles); // network initialisation KohonenMap.Train(); // network training KohonenMap.Render(); // map image generation KohonenMap.ShowTrainPatterns(); // show captions on the map for each element of the training set KohonenMap.ShowBMP(); // show the picture on the chart }
and one more modification - just in case, make the ReadCSVData function a bool too.
and check for mismatch between the header dimensions and the read next data line
PS.
I have already made all these manipulations with the class, so to say, finalised small things.But still your CSOM class is just awesome. Thanks.
and one more modification - just in case - make the ReadCSVData function bool too.
and check for mismatch between the header dimensions and the read next line of data
PS.
I have already made all these manipulations with the class, so to say, finalised the little things.
Thank you very much for your interest and useful recommendations.
I understand about KohonenMap.InitParameters, it is obviously a mistake.
Of course, the final class should be corrected as you suggested, it will be much more beautiful.
Please attach what you have got, we will replace it in the article.
One of the best articles on MQL5. And in a practical sense especially.
Thank you!
Please attach what you got, we will replace it in the article.
attached. list of changes:
1. small change in function cIntBMP::Show(int aX, int aY, string aBMPFileName, string aObjectName, bool aFromImages=true)
2. added to the main script
#import "shell32.dll" int ShellExecuteW(int hwnd, string oper, string prog, string param, string dir, int show); #import input bool OpenAfterAnaliz=true; // opening the map folder after completion
Changes in CSOM class
1. Added CSOM::HideChart function - it dims the chart, grid, etc. under the background colour
2. Added parameters m_chart, m_wnd, m_x0, m_y0 - indicating on which chart and which window to display maps.
+ prefix of object names m_sID. The prefix is automatically taken by file name, otherwise it is assigned "SOM"
3. Maps are written to the folder named m_sID
4. The names of bmp files are given by the name of the training pattern column .
4. Changed CSOM::ShowBMP function - maps are not copied to the Images folder, but remain in Files (otherwise it is very time-consuming)
5. Instead of CSOM::NetDeinit function - there is now CSOM::HideBMP function
7. CSOM::ReadCSVData function is reconfigured to read the file so that the first column is the names column
6. Added flag to CSOM::Train function to show intermediate maps CSOM::Train( bool bShowProgress)
8. In CSOM::Train function, intermediate data is displayed every 2 seconds instead of iterations,
and also progress notification is moved from the log to Comment
9. Some variable names are shortened and functions are categorised.
Bmp rendering slows down the process very much. So it is better not to use it unnecessarily.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
New article Using Self-Organizing Feature Maps (Kohonen Maps) in MetaTrader 5 is published:
Author: MetaQuotes