How to use fmincon for constrained maximum likelihood?

4 Ansichten (letzte 30 Tage)
MRC
MRC am 12 Feb. 2014
Beantwortet: Alan Weiss am 12 Feb. 2014
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?

Akzeptierte Antwort

Alan Weiss
Alan Weiss am 12 Feb. 2014
I ran exactly the code you gave with your data. fmincon ran to completion:
First-order Norm of
Iter F-count f(x) Feasibility optimality step
0 6 1.503710e+03 0.000e+00 1.317e+03
User objective function returned NaN; trying a new point...
1 14 1.052526e+03 0.000e+00 1.146e+03 1.602e+02
User objective function returned NaN; trying a new point...
2 29 2.470200e+02 0.000e+00 1.015e+02 5.340e+00
3 35 8.972820e+01 0.000e+00 5.300e+01 4.382e+00
4 41 6.477636e+01 0.000e+00 1.000e+01 2.883e+00
5 47 6.067017e+01 0.000e+00 1.829e+01 8.142e-01
6 53 5.640428e+01 0.000e+00 2.277e+01 8.831e-01
7 59 4.446661e+01 0.000e+00 2.729e+01 2.578e+00
8 65 3.106304e+01 0.000e+00 2.037e+01 3.292e+00
9 72 2.835120e+01 0.000e+00 8.090e+00 6.124e-01
10 78 2.596154e+01 0.000e+00 1.259e+00 1.105e+00
11 84 2.594904e+01 0.000e+00 2.985e-01 2.495e-02
12 90 2.594832e+01 0.000e+00 1.000e-01 5.350e-03
13 96 2.594832e+01 0.000e+00 1.995e-02 6.247e-04
14 102 2.594832e+01 0.000e+00 1.996e-04 3.078e-05
15 108 2.594832e+01 0.000e+00 3.789e-06 6.280e-06
16 114 2.594832e+01 0.000e+00 2.000e-06 2.072e-06
17 121 2.594832e+01 0.000e+00 1.780e-06 1.765e-07
18 127 2.594832e+01 0.000e+00 2.175e-06 5.074e-08
19 135 2.594832e+01 0.000e+00 1.263e-06 6.788e-08
20 147 2.594832e+01 0.000e+00 1.582e-06 3.423e-08
21 156 2.594832e+01 0.000e+00 1.780e-06 7.848e-09
Local minimum possible. Constraints satisfied.
fmincon stopped because the size of the current step is less than
the selected value of the step size tolerance and constraints are
satisfied to within the default value of the constraint tolerance.
So unless you give us the error message you saw, I regard that part of the question as answered.
For the second question: no, you cannot tell if there are other local minima by looking at the result of the first minimization run.
For more details, see Local Vs. Global Optima.
Alan Weiss
MATLAB mathematical toolbox documentation

Weitere Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by