How to use fmincon for constrained maximum likelihood?
Show older comments
Hi, I'm trying to solve a constrained minimization problem but I get several error messages. Could you help me in adjusting the code? Thanks!
clear all
n=2;
thetatrue=[1 1 2 2 0.2];
mu = [0 0]; %mean and variance covariance matrix
sd = [1 thetatrue(2*n+1); thetatrue(2*n+1) 1];
load data
X=data(:,1:n);
Y=data(:,n+1:size(data,2));
B1(:,2)=-X(:,1);
B1(:,1)=-1;
B2(:,2)=-X(:,2);
B2(:,1)=-1;
C1=(all(bsxfun(@eq,Y,[0 0]),2));
C2=1-C1;
cdf=@(x) mvncdf( [B1*[x(1);x(3)], B2*[x(2);x(4)] ] ,mu,[1 x(5); x(5) 1]);
options=optimset('Algorithm',...
'interior-point','Display','iter','MaxIter',10000,'TolX',10^-30,'TolFun',10^-30);
theta0=thetatrue;
[theta,fval,exitflag,output]=...
fmincon(@(x) log_lik(x,cdf,C1,C2),theta0,[],[],[],[],[-Inf; -Inf; -Inf; -Inf; -1], ...
[+Inf; +Inf; +Inf; +Inf; 1],[],options);
And
function val=log_lik(theta,cdf,C1,C2)
g=cdf(theta);
val=-sum(C1.*log(g)+C2.*log(1-g));
I have also another question: from the theory I know that the set of global minimizers could be non singleton; is there a way to understand it from the results of the optimization procedure?
Accepted Answer
More Answers (0)
Categories
Find more on Solver Outputs and Iterative Display in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!