fmincon and normal distribution log likelihood
7 views (last 30 days)
Show older comments
I seem to be having a problem with getting fmincon to solve for the normal log likelihood.
I've generated random numbers with known mean and variance:
t=10000;
xbar = 0.5;
sigmabar = 0.10;
x = xbar + sigmabar*randn(t,1); %generate random numbers
I then tried solving for N(muhat, sigmahat^2) using fmincon. I expect that muhat w ill be approximately the same as xbar and sigmahat as sigmabar. To do this, I first write the normal log likelihood as follows
function LL = normlgl(theta,data)
mu = theta(1);
sig = theta(2);
l=-0.5*log(2*pi)-log(sig)-0.5*( (data-mu)/sig ).^2;
LL = sum(l);
Finally, I minimize normlgl using some starting values (theta0) and setting some arbitrary lower and upper bounds.
theta0 = [3;-1];
lb = [-10;0.001];
ub = [10;100];
[thetahat,fval,exitflag] = fmincon('normlgl',theta0,[],[],[],[],lb,ub,[],[],x);
It doesn't seem to work. thetahat is always giving me theta0. I've tried using fminsearch and fminunc without the constraints but that didn't help.
Any ideas?
0 Comments
Answers (1)
Seth DeLand
on 16 Feb 2012
Hi Jimmy,
It looks like the way you have your optimization set up, you're trying to maximize the value of LL. However, all of the optimization solvers attempt to minimize the objective function.
Adding a minus sign so that:
LL = -sum(l);
gave me the expected answer.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!