Out of memory during calculating covariance norm matrix

1 回表示 (過去 30 日間)
K Ashwini
K Ashwini 2019 年 2 月 13 日
編集済み: Jan 2019 年 2 月 14 日
sumX=0;
for j=1:N
sumX=sumX+X(:,j);
end
Xave=sumX/N;
Cov=0;
for j=1:N
Cov=Cov+(X(:,j)-Xave)*(X(:,j)-Xave)';
end
Cov=Cov/N;
A=inv(Cov);
While running this code I am getting the error out of memory.I have tried the option of changing the settings in Preferences but still getting the same message.
Please help me to solve it out.
  2 件のコメント
Steven Lord
Steven Lord 2019 年 2 月 13 日
What size is X and what is the value of N?
What release of MATLAB are you using? Is it a 32-bit release or a 64-bit?
On which line is the "Out of memory" error thrown? Is it the line where you add to Cov in the second for loop, on the line where you call inv, or some other line?
K Ashwini
K Ashwini 2019 年 2 月 14 日
X is 128541*2
N=length(X(1,:)) => N=2
Matlab R2016a
64-bit
Cov=Cov+(X(:,j)-Xave)*(X(:,j)-Xave)'; In this line the error is shown.

サインインしてコメントする。

採用された回答

Jan
Jan 2019 年 2 月 14 日
編集済み: Jan 2019 年 2 月 14 日
The wanted 128'541*128'541 matrix has 16'522'788'681 elements and it needs 132'182'309'448 Bytes of RAM: 132 GB. As a rule of thumb having the double size of memory is useful. Are you working on a 256 GB machine?
These claculations are very easy and should be the first you do, if you observe a message, that the RAM is exhausted.
By the way: You can simplify
sumX=0;
for j=1:N
sumX=sumX+X(:,j);
end
Xave=sumX/N;
to:
Xave = sum(X, 2) / N;
% Or: Xave = mean(X, 2)
Please read: doc inv : An explicit inverting is rarely useful.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by