交易中的机器学习:理论、模型、实践和算法交易 - 页 3279

 
Alexander Ivanov #:
我不害怕

这就对了

 
Grigori.S.B #:

这也是理所当然的。

这将是来自现实世界的噩耗。

 

我想在一个长字符串中快速找到相似的短字符串。

有可能优化使用 Alglib 吗?

#include <Math\Alglib\statistics.mqh> // https://www.mql5.com/ru/code/11077

const vector<double> GetCorr( const CMatrixDouble &Matrix, const vector<double> &Pattern )
{
  CMatrixDouble Vector;
  CMatrixDouble Corr;
  
  Vector.Col(0, Pattern);

  CBaseStat::PearsonCorrM2(Vector, Matrix, Matrix.Rows(), 1, Matrix.Cols(), Corr);
  
  return(Corr.Row(0));
}

#property script_show_inputs

input int inRows = 300; // Длина короткой строки
input int inCols = 1000000; // Длина длинной строки

void FillArray( double &Array[], const int Amount )
{
  for (uint i = ArrayResize(Array, Amount); (bool)i--;)
    Array[i] = MathRand();
}

void FillMatrix( CMatrixDouble &Matrix, const double &Array[], const int Rows )
{
  Matrix.Resize(Rows, ArraySize(Array) + 1 - Rows);

  double ColArray[];
  vector<double> Vector;
  
  for (uint i = (uint)Matrix.Cols(); (bool)i--;)
  {
    ArrayCopy(ColArray, Array, 0, i, Rows);
    Vector.Swap(ColArray);
    
    Matrix.Col(i, Vector);
  }
}

void FillData( double &Array[], double &Pattern[], CMatrixDouble &Matrix, const int Rows, const int Cols )
{
  FillArray(Array, Cols + Rows - 1);
  FillArray(Pattern, Rows);

  FillMatrix(Matrix, Array, Rows);    
}

#define  TOSTRING(A) #A + " = " + (string)(A) + " "

// Поиск похожей строки в длинной строке.
void OnStart()
{  
  if (inRows < inCols)
  {
    PrintCPU(); // https://www.mql5.com/ru/forum/86386/page3256#comment_49538685
    
    double Array[]; // Длинная строка, где будет искать.
    double Pattern[]; // Короткая строка, с которой будем сравнивать.
    CMatrixDouble Matrix;
    
    FillData(Array, Pattern, Matrix, inRows, inCols); // Заполнили данные.
            
    Print(TOSTRING(inRows) + TOSTRING(inCols));

    vector<double> vPattern;  
    vPattern.Assign(Pattern);

    ulong StartTime, StartMemory; // https://www.mql5.com/ru/forum/86386/page3256#comment_49538685

    BENCH(vector<double> Vector1 = GetCorr(Matrix, vPattern))
//    BENCH(vector<double> Vector2 = GetCorr(Array, Pattern))
  
//    Print(TOSTRING(IsEqual(Vector1, Vector2)));
  }      
}


结果。

EX5: 4000 AVX Release.
TerminalInfoString(TERMINAL_CPU_NAME) = Intel Core i7-2700 K  @ 3.50 GHz 
TerminalInfoInteger(TERMINAL_CPU_CORES) = 8 
TerminalInfoString(TERMINAL_CPU_ARCHITECTURE) = AVX 
inRows = 300 inCols = 1000000 
vector<double> Vector1 = GetCorr(Matrix, vPattern) - 6725703 mcs, 8 MB

通过 Alglib 实现在第一百万个字符串中搜索相似短字符串 (300) 的时间超过六秒。NumPy 可以做到吗?

 
fxsaber #:

试图在长字符串中快速找到相似的短字符串。

使用 Alglib 是否更为理想?


结果。

通过 Alglib 在百万分之一的字符串中搜索与短字符串 (300) 类似的字符串需要 8 秒多的时间。NumPy 可以做到吗?

你将如何评估得到的矩阵?我不明白这种评估的原理。

 
Forester #:
你又将如何评估得出的 300*1000000 矩阵?我不明白这种估算的原理。

  1. 一行为 1 000 000。
  2. 我们取区间 [0..299] 中的值,将其放入 300*1000000 矩阵的第一列。
  3. 取区间 [1...300] 中的值,放入 300x1000000 矩阵的第二列。
  4. 以此类推。
计算该矩阵与 300 处某些模式的相关性。输出结果是相应皮尔逊系数的百万分之一向量。
 
fxsaber #:
该实现在 Alglib 中搜索与 字符串类似的第一百万个字符串 需要6 秒 多的时间。

我的平均时间也是 6 秒左右。

我已经运行了几次。

 system.time({
+   find_cor(y,x)
+ })
   user  system elapsed 
   4.15    0.03    5.70 
> system.time({
+   find_cor(y,x)
+ })
   user  system elapsed 
   4.38    0.02    5.16 
> system.time({
+   find_cor(y,x)
+ })
   user  system elapsed 
   4.18    0.01    6.10 
> system.time({
+   find_cor(y,x)
+ })
   user  system elapsed 
   4.08    0.00    5.99 

但我用的是最普通的方法,没有寻找任何火箭科学的解决方案。

 
mytarmailS #:

我的平均时间也是 6 秒左右。

我跑过几次

但我是按常规方法做的,没有寻找任何火箭科学的解决方案。

你用的是哪种 R?

微软的 R 使用英特尔的矢量和矩阵圣经....。

 
СанСаныч Фоменко #:

你的 R 是什么?

Microsoft R 使用英特尔矢量和矩阵圣经....。

有规律的...

但我在 R 中用 C++ 编写了函数。

 
mytarmailS #:

普通

我想知道微软 R + 英特尔 = 庞特还是真的更快?

 
СанСаныч Фоменко #:

我想知道微软 R + 英特尔 = 庞特还是真的更快?

我没试过,也很好奇。

但我感兴趣的是在任何操作上的总体速度提升,而不仅仅是矩阵和向量。