## how to do mle on custom mvnpdf ?

Asked by chao-hung huang

### chao-hung huang (view profile)

on 17 Mar 2019
Latest activity Answered by Jeff Miller

### Jeff Miller (view profile)

on 17 Mar 2019
Accepted Answer by Jeff Miller

### Jeff Miller (view profile)

Hi,
i'm trying to fit two correlated model with MVNpdf.
But it seems that the SIGMA of the function cannot set parameters there
mvnpdf(X,mu,SIGMA)
the model as below
%% S for dr_t
%% L for dl_t
Sx=S(1:end-1);Sy=S(2:end);
Lx=L(1:end-1);Ly=L(2:end);
diffL=Ly-Lx;diffS=Sy-Sx;
func=@(theta) -sum(log(mvnpdf([diffL diffS], ...
[theta(1)*(theta(2)-Lx)*delta_t theta(4)*(Lx-Sx)*delta_t], ...
[theta(3) theta(6);theta(5) theta(6)])));
param=fminsearch(func,[0.8 0.01 1 0.2 1 0]);
however, i find it doesn't work
it shows "SIGMA must be a square, symmetric, positive definite matrix" and Error in fminsearch.
Is there any solution ? Thanks !!

### Jeff Miller (view profile)

Answer by Jeff Miller

### Jeff Miller (view profile)

on 17 Mar 2019

I don't really understand what you are trying to do, but the error message "SIGMA must be a square, symmetric, positive definite matrix" suggests the problem. fminsearch is trying different theta values, and sometimes it tries values for which the sigma matrix [theta(3) theta(6);theta(5) theta(6)] is not positive definite.
Inside your error function (not an anonymous one),you will have to compute a legal SIGMA from whatever values fminsearch suggests. (To do that, you may need to re-parameterize the problem a little bit.) For example, fminsearch might try a negative value for theta(3), but variances have to be positive. So, for example, you might have something like
thiscovar = theta(6);
SIGMA(1,1) = abs(theta(3));
SIGMA(1,2) = thiscovar;
SIGMA(2,1) = thiscovar;
SIGMA(2,2) = abs(theta(5));
and then call mvnpdf with this computed SIGMA.