You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Background
I am current trying to use MQL4's AlgLib library made by MetaQuotes, albeit with some slight edits. I am making some changes to the CMatrixDouble Class to in the matrix.mqh file to make the CMatrixDouble class easier to use.
Current Changes to class declaration:
//+------------------------------------------------------------------+
//| Matrix (double) |
//+------------------------------------------------------------------+
class CMatrixDouble
{
private:
//--- array
CRowDouble m_rows[];
public:
int num_rows;
int num_cols;
//--- constructors, destructor
CMatrixDouble(void);
CMatrixDouble(const CMatrixDouble &that);
CMatrixDouble(const int rows);
CMatrixDouble(const int rows,const int cols);
~CMatrixDouble(void);
//--- methods
int Size(void) const;
void Resize(const int n,const int m);
//--- overloading
CRowDouble *operator[](const int i) const;
void operator=(const CMatrixDouble &m);
CMatrixDouble *operator+(const CMatrixDouble &m) const;
CMatrixDouble *operator-() const;
CMatrixDouble *operator-(const CMatrixDouble &m) const;
};
New Methods:
CMatrixDouble::CMatrixDouble(const CMatrixDouble &that){
this = that;
}
CMatrixDouble *CMatrixDouble::operator+(const CMatrixDouble &m) const{
int rows = this.num_rows;
int cols = this.num_cols;
CMatrixDouble result = CMatrixDouble(rows, cols);
if(rows != m.num_rows || cols != m.num_cols){return GetPointer(result);}
for(int i=0; i < rows; i++){
for(int j=0; j < cols; j++){
result[i].Set(j, this[i][j] + m[i][j]);
}
}
return GetPointer(result);
}
CMatrixDouble *CMatrixDouble::operator-() const{
int rows = this.num_rows;
int cols = this.num_cols;
CMatrixDouble result = CMatrixDouble(rows, cols);
for(int i=0; i < rows; i++){
for(int j=0; j < cols; j++){
result[i].Set(j, (-1)*this[i][j]);
}
}
return GetPointer(result);
}
CMatrixDouble *CMatrixDouble::operator-(const CMatrixDouble &m) const{
return this + -m;
}
Question
I am doing this, so I can code neural network related code, but I am not sure how to go about memory management, so I wanted to ask for some advice on what would be best practices dealing with functions that return the CMatrixDouble Objects & Pointers like this one:
CMatrixDouble Softmax_Backprop(CMatrixDouble &output, CMatrixDouble &Y){
//y_hat - y
return output - Y;
}
Another thing: Are there good resources for reading up on the best memory management tips for MQL4 and if there are any functions that help keep track of how much memory is in usage?
P.S: Criticism of how these new CMatrixDouble Class Methods are implemented are of course welcomed as well. Thank you!