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, огромен. Поэтому для начала имеет смысл рассмотреть наиболее простые и полезные функции, которые могут применяться в большинстве программ.
Reason: