NaN and Infs popping in my matrices after a few iterations of EM algorithm

1 回表示 (過去 30 日間)
Jérôme
Jérôme 2012 年 11 月 20 日
Hello ;
So, I'm implementing the EM algorithm in Matlab, but my matrices quickly end up contaminated by NaN and Inf values. I think it might be caused by matrix inversions, but I'm not sure it's the only reason.
Here is the code : em_algo.m http://pastebin.com/vJGqQPw7 iterates until convergence (which never happens due to my issue) and calls smoother.m http://pastebin.com/yD9Je37i at each iteration. The NaNs and Infs start popping around the ~8th iteration, usually.
I guess in there somewhere I'm doing something unholy with my matrices, but I really have no clue about what's wrong. I trust your expertise.
Thanks in advance for the help!

回答 (3 件)

José-Luis
José-Luis 2012 年 11 月 20 日
It sounds like you are running into numerical stability issues. Look at the following example, that might help you understand what is happening:
val = 1;
while (val ~= Inf)
val = val / 10^-100
end
The NaN's that pop up can be a result of
0/0

Jérôme
Jérôme 2012 年 11 月 22 日
Thanks José-Luis. Indeed, something like that might be the source of my problem. But I have a hard time finding out WHERE it happens in the code. :/
Another issue (or most likely another aspect of the same one) is the fact that some values seem to grow out of bonds which probably leads to Inf values. But again, I have no idea why this is happening.
  2 件のコメント
Walter Roberson
Walter Roberson 2012 年 11 月 22 日
dbstop if naninf
José-Luis
José-Luis 2012 年 11 月 23 日
編集済み: José-Luis 2012 年 11 月 23 日
If your matrices are close to rank deficient, and you invert them, then numerical problems can pop up.

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


Matt J
Matt J 2012 年 11 月 23 日
編集済み: Matt J 2012 年 11 月 23 日
Set a conditional breakpoint at line 45 (making it conditional on i==8 or whenever the NaNs start to pop up). When the code stops there, see whether inv(A) has sensible values.

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by