Dear Johannes,

The appearance of NaNs during convergence is usually no problem because the EM scheme will
reset itself and start again with smaller update steps.  My previous email was about NaNs in the
posterior probabilities (these are perfectly OK and usually report connections where the prior
variance is zero). However, if the NaNs appear in the conditional covariance (Cp), where the prior
variance was not zero, this suggests a problem. This problem can occur occasionally with highly
nonlinear (brittle) DCMs (e.g., nonlinear DCMs that include interactions among hidden states).

The solution is usually to use increase the shrinkage priors or reformulate the model.

Alternatively, it may be the case that the matrix exponential is not converging properly. You can check
this by always using the (more robust) Pade approximation. This would involve changing spm_expm.m.
However, it is possible that even the Pade approximation fails, in which case you could increase the
regularization of the EM scheme.

I am not sure which version of SPM you are using but (using our current SVN version) you can enforce
the Pade appropriation in spm_expm.m by changing the first line to

if nargin == 1 || nargin == 2


You can increase the regularization in spm_nsli_GN by using

       % decrease regularization
        %------------------------------------------------------------------
        v     = min(v + 1/2,8);
        str   =
'EM:(+)';
       
   
else
 
       
% reset expansion point
        %------------------------------------------------------------------
        p     = C.p;
        h     = C.h;
        Cp    = C.Cp;
 
       
% and increase regularization
        %------------------------------------------------------------------
        v   = min(v - 2,-4);
        str =
'EM:(-)';
       
   
end



I hope this helps,

With very best wishes,

Karl


PS: In the next but one update we will be releasing an upgrade of DCM for fMRI which uses a more robust
(and much faster) optimization scheme and a slight reformulation of the hemodynamic model to
avoid some of the problems encountered with 'brittle' DCMs.


At 14:36 05/01/2010, Klaas Enno Stephan wrote:
Dear Johannes,

In response to your questions:

1. Cp enters the computation of F via spm_logdet (line 330 of spm_nlsi_GN).  If Cp is NaN, the resulting value of the log determinant should be numerically almost indistinguishable compared to the case when Cp = realmin; in this case you should indeed not notice a difference in F. 

2. I think that should be ok.

3.  This will depend on where in spm_expm the numerical problems occur.  You might be able to exploit the relations realmin > 0 and inf > realmax?

I cc this email to Karl in case he has additional comments on this issue.

All the very best,
Klaas




Von: Johannes Tuennerhoff <[log in to unmask]>
An: [log in to unmask]
Gesendet: Dienstag, den 22. Dezember 2009, 13:58:22 Uhr
Betreff: [SPM] DCM: NaNs in Cp

Dear SPMers,
I am wondering about NaNs in Cp that occur in some cases. I do get a free energy F but the variance Cp is only containing NaNs.
By debugging the code I found that it seems to be due to an overflow/underflow with respect to realmax/realmin occuring in spm_expm.m, however the Cp is only in some of the iteration steps NaN.
So my questions are:
 
1. If I get it right, according to Prof. Karl Friston ( https://www.jiscmail.ac.uk/cgi-bin/wa.exe?A2=ind0804&L=SPM&P=R49210 ), I can still use the free energy for inferences. Is that correct?
 
2. Since I need Cp and the NaNs occur only in some iteration steps, would it be a reasonable fix to change the criterion for convergence in spm_nlsi_GN.m line 423:

if k > 2 && dF < 1e-2

to:

if k > 2 && dF < 1e-2 && length(find(isnan(Cp)==1))==0
so that the EM algorithm continues until a step where Cp has numbers is reached? (Apparently that doesn't change the resulting F.)
In case that would be an ok thing to do, would I also need to change the line 316 ?:

if dF < 1e-2, break, end 
3. Does anyone know how to get around a realmax-overflow/realmin-underflow problem?
 
I'd really appreciate any ideas and comments.
Thank you.
Regards
Johannes

__________________________________________________
Do You Yahoo!?
Sie sind Spam leid? Yahoo! Mail verfügt über einen herausragenden Schutz gegen Massenmails.
http://mail.yahoo.com