Weighted PCA throws error: Input to SVD must not contain NaN or Inf.

30 ビュー (過去 30 日間)
Daniel Ringel
Daniel Ringel 2017 年 8 月 9 日
コメント済み: Daniel Ringel 2017 年 8 月 17 日
Hello, I started to use Matlab's built in PCA on a large data set in terms of variables (around 70 Observations but 100,000 variables in matrix M).
Using standard PCA I get results (N-1 PC's).
[coeff,scores,latent,~,explained] = pca(M);
When I run weighted PCA on the same data
[wcoeff,scores,latent,~,explained] = pca(M,'VariableWeights','variance');
I get the following error message:
Error using svd
Input to SVD must not contain NaN or Inf.
Error in pca>localSVD (line 477)
[U,sigma,coeff] = svd(x,'econ');
Error in pca (line 347)
[U,sigma, coeff, wasNaN] = localSVD(x, n,...
Error in ScriptA (line 62)
[wcoeff,scores,latent,~,explained] = pca(M,'VariableWeights','variance');
What am I doing wrong? Or what is the problem with matrix M that I need to resolve? Thank you, Daniel

採用された回答

Faiz Gouri
Faiz Gouri 2017 年 8 月 17 日
Your input matrix probably contains infinity or not a number(NaN). Set a breakpoint in your file then run it again. When MATLAB reaches the breakpoint, look at the input matrix values. It will contain at least one element that is Inf, NaN, or -Inf. The SVD function doesn't know how to compute the singular value decomposition of a matrix with a nonfinite element. If you are updating matrix in a loop, the first iteration may not be the one that's throwing the error; in that case, or once you've determined that input matrix does actually contain a nonfinite value, set an error breakpoint to stop as soon as an Inf or NaN value is created. This will indicate where the nonfinite element of X is being introduced. Then figure out, based on your knowledge of your algorithm, how to prevent the nonfinite value from being introduced.
Hope this helps!
  1 件のコメント
Daniel Ringel
Daniel Ringel 2017 年 8 月 17 日
Thank your for your help. My initial input matrix contains no NaN or Inf values. So they have to be generated during the PCA processing. I wonder why...?
Are you suggesting I manipulate the built in Matlab PCA function by adding break points? How would I do that?

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDimensionality Reduction and Feature Extraction についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by