Date: Feb 27, 2013 11:47 AM
Author: Steven Lord
Subject: Re: Alternative solution for NAN

"Carl S." <tkittler@gmail.com> wrote in message

news:kgkurb$1t8$1@newscl01ah.mathworks.com...

> "Torsten" wrote in message <kgku2t$t2g$1@newscl01ah.mathworks.com>...

*snip*

>> The matrix N you get after the while loop is a scalar multiple of the

>> identity matrix and in general has nothing in common with your original

>> matrix N. You will have to find out why eig produces NaN values for your

>> original matrix N. Are you sure all elements of N are finite ? Best

>> wishes

>> Torsten.

>

> Yes, Torsten, they are finite

>

> My goal is to fit means(mu) and standard deviations(N) to Gaussian shape.

> The codes that I wrote above are from the function ;

>

> function res=MultivariateGaussianPDF(x,mu,N)

> while(det(N) == 0)

1) Don't use DET to test for singularity. This matrix:

A = 1e-10*eye(400);

has determinant 0 (due to underflow) but it's a scaled identity matrix,

which is about as well-behaved as you can get. If you _must_ test for

singularity, check with COND or RCOND.

2) Don't test a floating-point number for exact, bit-for-bit equality unless

you need exact, bit-for-bit equality. Compare with a tolerance instead.

> N=(1e-10.*randi(1,size(N)))*eye(size(N));

> end

>

> [M,d]=size(x);

> [U,D]=eig(N); % <=causes NAN problem :((

Show the group a SMALL matrix N with which you can reproduce this behavior.

*snip*

3) If you have Statistics Toolbox, do one of these functions do what you

want?

http://www.mathworks.com/help/stats/multivariate-normal-distribution-1.html

http://www.mathworks.com/help/stats/normal-distribution-1.html

If not, please explain more _in words not code or equations_ specifically

what you mean/are trying to do when you say you want to fit means and

standard deviations to a Gaussian shape.

--

Steve Lord

slord@mathworks.com

To contact Technical Support use the Contact Us link on

http://www.mathworks.com