Watch
1
0
Fork
You've already forked NeuroBook
0
forked from rosh/NeuroBook
NeuroBook/Include/realization/positionencoder.mqh

112 lines
8.7 KiB
MQL5

2025-05-30 16:12:30 +02:00
<EFBFBD><EFBFBD>//+------------------------------------------------------------------+
//| positionencoder.mqh |
//| Copyright 2021, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Ltd."
#property link "https://www.mql5.com"
//+------------------------------------------------------------------+
//| Connect libraries |
//+------------------------------------------------------------------+
#include "buffer.mqh"
//+------------------------------------------------------------------+
//| Class CPositionEncoder |
//| Purpose: Positional encoding class |
//+------------------------------------------------------------------+
class CPositionEncoder : public CBufferType
{
protected:
ulong m_iCount;
ulong m_iDimension;
public:
CPositionEncoder(void) {};
~CPositionEncoder(void) {};
//---
virtual bool InitEncoder(ulong count, ulong dimension); // Initialization method
virtual bool AddEncoder(CBufferType *&buffer); // Method for adding positional copying to input data
//--- File handling method
virtual bool Save(const int file_handle);
virtual bool Load(const int file_handle);
};
//+------------------------------------------------------------------+
//| Initialization method |
//+------------------------------------------------------------------+
bool CPositionEncoder::InitEncoder(ulong count, ulong dimension)
{
//--- Save constants
m_iCount = count;
m_iDimension = dimension;
//--- Prepare buffer
if(!m_mMatrix.Resize(count, dimension))
return false;
//--- Fill buffer with positional encoding labels
for(int r = 0; r < (int)count; r++)
{
for(int c = 0; c < (int)dimension; c++)
{
TYPE value = (TYPE)(r / pow(1000, 2 * c / dimension));
switch(c % 2)
{
case 0:
m_mMatrix[r, c] = (TYPE)MathSin(value);
break;
case 1:
m_mMatrix[r, c] = (TYPE)MathCos(value);
break;
}