//+------------------------------------------------------------------+ //| Pearson product-moment correlation matrix | //| INPUT PARAMETERS: | //| X - array[N,M], sample matrix: | //| * J-th column corresponds to J-th variable | //| * I-th row corresponds to I-th observation | //| N - N>=0, number of observations: | //| * if given, only leading N rows of X are used | //| * if not given, automatically determined from input | //| size | //| M - M>0, number of variables: | //| * if given, only leading M columns of X are used | //| * if not given, automatically determined from input | //| size | //| OUTPUT PARAMETERS: | //| C - array[M,M], correlation matrix (zero if N=0 or N=1) | //+------------------------------------------------------------------+ static bool CBaseStat::PearsonCorrM(const CMatrixDouble &cx,const int n, const int m,CMatrixDouble &c)
小 TF 内存溢出。16 个 Osu 和交换文件(Mac 上的交换文件)的内存溢出为 30 千兆。例如,有一个 50k x 50k 的相关矩阵。
显然,Python 有一些特殊性,因为 MQL 的算法是一样的。
这是一个正面变体。用筛子筛 得更快。
假设有一百万个条形图。字符串的长度为 10。那么 1000 万个双值的 1d-array 就是 80 Mb。- 好吧,就内存消耗而言,就 500 Mb 吧。我还有什么没考虑到的?
这一定是 Python 的一些特殊性,因为 MQL 的算法是一样的。
这是一个正面变体。筛分 速度更快。
假设有一百万条。字符串的长度为 10。那么 1000 万个双值的 1d-array 是 80 Mb。- 好吧,就内存消耗而言,就 500 Mb 吧。我还有什么没考虑到的?
所有行的矩阵与所有行的相关性被认为比循环(每隔一行与另一行)和偶数循环(每隔一行与所有行)快很多倍。这种算法有某种加速作用。我在相关计算的 alglib 版本上进行了检查。
把代码给我,让我们检查一下。
我认为 MathAbs () 似乎没有必要
这一定是 Python 的一些特殊性,因为 MQL 的算法是一样的。
这是一个正面变体。筛分 速度更快。
假设有一百万条。字符串的长度为 10。那么 1000 万个双值的 1d-array 是 80 Mb。- 好吧,就内存消耗而言,就 500 Mb 吧。我还有什么没考虑到的?
我自己也很困惑,Python 中没有一个库能计算出这个值,所以我最后也很困惑。
Pandas 会溢出内存,开销巨大。
Nampai 只会崩溃并杀死解释器会话:)而不会显示任何错误。把代码给我,我们来看看。
functions
PearsonCorrM - 所有行与所有行的相关性最快。
//+------------------------------------------------------------------+
//| Pearson product-moment correlation matrix |
//| INPUT PARAMETERS: |
//| X - array[N,M], sample matrix: |
//| * J-th column corresponds to J-th variable |
//| * I-th row corresponds to I-th observation |
//| N - N>=0, number of observations: |
//| * if given, only leading N rows of X are used |
//| * if not given, automatically determined from input |
//| size |
//| M - M>0, number of variables: |
//| * if given, only leading M columns of X are used |
//| * if not given, automatically determined from input |
//| size |
//| OUTPUT PARAMETERS: |
//| C - array[M,M], correlation matrix (zero if N=0 or N=1) |
//+------------------------------------------------------------------+
static bool CBaseStat::PearsonCorrM(const CMatrixDouble &cx,const int n,
const int m,CMatrixDouble &c)
PearsonCorr2 - 行与行之间的相关性。对于全矩阵:第 1 行与第 1 行之后的所有行进行检查,第 2 行与第 2 行之后的所有行进行检查,等等。
//| Pearson product-moment correlation coefficient |
//| Input parameters: |
//| X - sample 1 (array indexes: [0..N-1]) |
//| Y - sample 2 (array indexes: [0..N-1]) |
//| N - N>=0, sample size: |
//| * if given, only N leading elements of X/Y are |
//| processed |
//| * if not given, automatically determined from |
//| input sizes |
//| Result: |
//| Pearson product-moment correlation coefficient |
//| (zero for N=0 or N=1) |
//+------------------------------------------------------------------+
static double CBaseStat::PearsonCorr2(const double &cx[],const double &cy[],
const int n)
通过 PearsonCorrM2,您可以将全矩阵写入 1 个矩阵和另一个要检查的行。但这显然是多余的工作,因为第 10 行与第 10 行以上各行的相关性已经计算出来了。
const int n,const int m1,const int m2,
CMatrixDouble &c)
一个 20k*20k 的 Numpy 矩阵重达 2GB。
4 亿个双数重达 3 千兆。
MathAbs () 在我看来是多余的。
您也可以单独检查符号。这不是重点。
4 亿个双数字重达 3 千兆字节。
这也是可以理解的,毕竟没有足够的内存来存储这些快乐。