Matrices and vectors in MQL5 - page 2

 
Dominik Egert #:
Yes, I understand. But shouldn't this be the same result then??

for this specific case yes but for other complex stuff no

 
Lorentzos Roussos #:

for this specific case yes but for other complex stuff no

But that's what I mean, as far as my imagination goes, I cannot think of a use case where you actually need that.

Edit:
And for this specific case, the multiplication is actually one AVX instruction.

Compare that to the loop...
 
Dominik Egert #:
But that's what I mean, as far as my imagination goes, I cannot think of a use case where you actually need that.

i've used it somewhere if i recall , something with distances .

And the ceo is playing around with ai so this came about from a need probably .

These libraries are supposed to be "faster" than any custom solution .

Also in this case you probably can get the benefit of initializing inside a compute unit if you utilize open cl , i assume 

although , you will still initialize sequentially ... hmm
 
Lorentzos Roussos #:

i've used it somewhere if i recall , something with distances .

And the ceo is playing around with ai so this came about from a need probably .

These libraries are supposed to be "faster" than any custom solution .

Also in this case you probably can get the benefit of initializing inside a compute unit if you utilize open cl , i assume 

although , you will still initialize sequentially ... hmm
There we go...

I am convinced, the API design is incomplete and should have a different shape.

Edit:

Nah, open CL does not support vector from MQL, it's a different language. - No advantage and use case for MQL structures/objects
 
or we can't see what's coming up and it has to be this way 
 
Lorentzos Roussos #:
or we can't see what's coming up and it has to be this way 
Since 2 years?

Edit:

Thank you anyways for your thoughts
 
Dominik Egert #:
Since 2 years?

Edit:

Thank you anyways for your thoughts

yeah , or its abandoned  😅

also , this stuff is brutal so 
 
Anil Varma #:

@Lorentzos Roussos @Dominik Egert

I was just about to start with matrices and vectors, but reading this thread got me thinking again.

Tell me honestly, is it worth spending time to learn them? The documentation is very poor at explaining the correct ways to use them.

Example from https://www.mql5.com/en/docs/matrix/matrix_machine_learning/matrix_regressionmetrics

Another example at https://www.mql5.com/en/book/common/matrices/matrices_sle is used without the input parameter const vector& vctName!!!

So which one is correct?

Below is my first attempt and I got inconclusive results.

results :

Any clues as to what is wrong here?

The book was written in 2021-2022. Since then, MQL5 has changed a lot. In particular, the functions for working with matrices have changed: in RegressionMetric, the prototype has changed - a new first parameter has been added.

The source code of the MatrixForexBasket.mq5 example was corrected for it immediately after the announcement of the changes - see the 4th part in the codebase - https://www.mql5.com/en/code/45593.

   ...
   // build a model of best balance - stable profit on every bar
   vector model(BarCount - BarOffset, ConstantGrow);

   ...
   // now estimate the quality of solution
   if(BarOffset > 0)
   {
      // NB: MQL5 doesn't have Split for vectors!
      // NB: MQL5 can't assign vector to matrix or matrix to vector!
      // make a copy of balance
      vector backtest = balance;
      // only historic in-sample bars are used for backtest estimation
      backtest.Resize(BarCount - BarOffset);
      // prepare forward out-of-sample part of the bars manually
      vector forward(BarOffset);
      for(int i = 0; i < BarOffset; ++i)
      {
         forward[i] = balance[BarCount - BarOffset + i];
      }
      // calculate regression metrics for backtest and forward
      Print("Backtest R2 = ", backtest.RegressionMetric(model, REGRESSION_R2));
      model.Resize(BarOffset);
      model += BarCount - BarOffset;
      Print("Forward R2 = ", forward.RegressionMetric(model, REGRESSION_R2));
   }
   else
   {
      Print("R2 = ", balance.RegressionMetric(model, REGRESSION_R2));
   }
   ...
Программирование на MQL5 для трейдеров — исходные коды из книги. Часть 4
Программирование на MQL5 для трейдеров — исходные коды из книги. Часть 4
  • www.mql5.com
В четвертой части книги мы сосредоточимся на освоении встроенных функций (MQL5 API) и будем последовательно углубляться в специализированные подсистемы. Перечень технологий и функциональности, доступных любой программе на MQL5, огромен. Поэтому для начала имеет смысл рассмотреть наиболее простые и полезные функции, которые могут применяться в большинстве программ.
 

Matrix Factorization: The Basics

Matrix Factorization: The Basics

In this article, we will talk about matrix calculations. Dear readers, do not rush to refuse reading this article, thinking that we will talk about something purely mathematical and too complicated. Contrary to what many people think, a good programmer is not someone who writes a giant program that only they can understand, or someone who writes code in a trendy programming language. A real and good programmer understands that a computer is nothing more than a computing machine to which we can tell how computations should be performed. It doesn't matter what exactly we are creating, it can be a simple text editor that does not contain any mathematical code. But this is just an illusion. Even a text editor contains a fair amount of math in its code, especially if it has a spell checker built into it.
Matrix Factorization: The Basics
Matrix Factorization: The Basics
  • www.mql5.com
Since the goal here is didactic, we will proceed as simply as possible. That is, we will implement only what we need: matrix multiplication. You will see today that this is enough to simulate matrix-scalar multiplication. The most significant difficulty that many people encounter when implementing code using matrix factorization is this: unlike scalar factorization, where in almost all cases the order of the factors does not change the result, this is not the case when using matrices.
 

Matrix Factorization: A more practical modeling

Matrix Factorization: A more practical modelingMatrix Factorization: A more practical modeling

In the previous article "Matrix Factorization: The Basics", I talked a little about how you, my dear readers, can use matrices in your general calculations. However, at that time I wanted you to understand how the calculations were done, so I didn't pay much attention to creating the correct model of the matrices.
Matrix Factorization: A more practical modeling
Matrix Factorization: A more practical modeling
  • www.mql5.com
You might not have noticed that the matrix modeling was a little strange, since only columns were specified, not rows and columns. This looks very strange when reading the code that performs matrix factorizations. If you were expecting to see the rows and columns listed, you might get confused when trying to factorize. Moreover, this matrix modeling method is not the best. This is because when we model matrices in this way, we encounter some limitations that force us to use other methods or functions that would not be necessary if the modeling were done in a more appropriate way.