Error: objective function (feval) is not zero or at optimum.

1 次查看(过去 30 天)
I am trying to use mle estimation to estimate parameters of customized pdf. I am using two methods: mle function and fmincon. The function I am trying to estimate has the following sotchastic distribution: f(x)=(1-c)/(sqrt(2*pi*)*op)*exp(-power(x-up,2)*0.5*op^-2) +(c)/(sqrt(2*pi*)*oz)*exp(-power(x-up-uz,2)*0.5*op^-2)
where c is a bionomial random variable.
the objective function using mle and fmincon does not progress to 0 (feval at the optimum is 4.7 e3). First optimality order is zero. This is the code that I have used for fmincon :
z=x(1,:);
options = optimoptions('fmincon','Display','iter-detailed','Algorithm','sqp','MaxIter',3e4,'MaxFunctionEvaluations',3e8,....
'StepTolerance',1e-10,'TolFun',1e-3,'OptimalityTolerance',1e-5,'ConstraintTolerance',1e-3 ,'FiniteDifferenceType','central')
problem.options = options;
% rng('default');
problem.solver = 'fmincon';%'TolX',10^-4,'TolFun',10^-4,
problem.objective = @(y)norm_likelhood_fun(y,z);%norm_likelhood_multi_fun(y,z);%
problem.x0 = rand(5,1);
problem.nonlcon = @(y) cdf_norm(y,z);
problem.A = [];
problem.b = [];
problem.Aeq = [];
problem.beq = [];
problem.lb = 0*ones(5,1);
problem.ub = 1*ones(5,1);%[0.99 0.99 0.99 0.99 0.99];
gs = GlobalSearch;
ms=MultiStart;
%problem.ub = [1,1,1,1,1];
%for j=1:1
problem.x0= [0.1 1e-2 0 0.05 1e-2];
%problem.x0 = [0;0.1;0;0.2;0.01];
[y,feval ,exitflag,output,lam]=fmincon(problem)
yy=[u1;o1;u2;o2;ep]
function l1=norm_likelhood_fun(y,z,cens,freq)
oz=sqrt(y(2).^2+y(4).^2);
x1=((1-y(5))/(sqrt(2*pi)*y(2)))*exp(-0.5*power(z(~cens)-y(1),2)/y(2)^2);
x2=(y(5)/(sqrt(2*pi)*oz))*exp(-0.5*power(z(~cens)-y(1)-y(3),2)/oz^2);
l1=-sum(log(x1+x2));
end
function [c,ceq]=cdf_norm(y,z)
oz=sqrt(y(2).^2+y(4).^2);
x1=((1-y(5))/(2))*(1+erf((z-y(1))/(y(2)*sqrt(2))));
x2=(y(5)/2)*(1+erf((z-y(1)-y(3))/(oz*sqrt(2))));
c=-1+x1+x2;
ceq=[];
end
I followed the recommendation on the below links:
However, the ouput that i got is this:
Iter Func-count Fval Feasibility Step Length Norm of First-order
step optimality
30 369 5.495456e+03 0.000e+00 1.000e+00 4.031e-03 2.805e+00
31 380 5.495456e+03 0.000e+00 1.000e+00 9.287e-03 3.505e+00
32 391 5.495455e+03 0.000e+00 1.000e+00 1.933e-02 3.550e+00
33 402 5.495455e+03 0.000e+00 1.000e+00 2.312e-02 3.031e+00
34 413 5.495455e+03 0.000e+00 1.000e+00 3.105e-03 1.810e-01
35 424 5.495455e+03 0.000e+00 1.000e+00 3.168e-03 5.573e-01
36 435 5.495455e+03 0.000e+00 1.000e+00 2.338e-03 7.707e-01
37 446 5.495455e+03 0.000e+00 1.000e+00 5.335e-03 9.047e-01
38 457 5.495455e+03 0.000e+00 1.000e+00 4.379e-03 6.183e-01
39 468 5.495455e+03 0.000e+00 1.000e+00 3.938e-03 1.542e-01
40 479 5.495455e+03 0.000e+00 1.000e+00 4.085e-03 1.323e-01
41 490 5.495455e+03 0.000e+00 1.000e+00 3.578e-03 9.856e-02
42 501 5.495455e+03 0.000e+00 1.000e+00 2.611e-03 4.071e-02
43 512 5.495455e+03 0.000e+00 1.000e+00 2.386e-03 5.575e-02
44 523 5.495455e+03 0.000e+00 1.000e+00 2.003e-03 1.303e-02
45 535 5.495455e+03 0.000e+00 7.000e-01 2.057e-03 5.140e-02
46 546 5.495455e+03 0.000e+00 1.000e+00 6.619e-05 1.113e-02
47 557 5.495455e+03 0.000e+00 1.000e+00 8.599e-04 5.128e-03
48 569 5.495455e+03 0.000e+00 7.000e-01 2.112e-03 2.619e-02
49 580 5.495455e+03 0.000e+00 1.000e+00 8.720e-04 1.873e-03
50 591 5.495455e+03 0.000e+00 1.000e+00 3.328e-04 8.088e-05
51 607 5.495455e+03 0.000e+00 1.681e-01 1.968e-05 4.356e-05
52 618 5.495455e+03 0.000e+00 1.000e+00 1.233e-05 5.707e-06
Optimization completed: The relative first-order optimality measure, 5.707383e-06,
is less than options.OptimalityTolerance = 1.000000e-05, and the relative maximum constraint
violation, 0.000000e+00, is less than options.ConstraintTolerance = 1.000000e-03.
y =
0.3264 0.4192 0 0.0033 0.0304
feval =
5.4955e+03
exitflag =
1
output =
struct with fields:
iterations: 52
funcCount: 618
algorithm: 'sqp'
message: '↵Local minimum found that satisfies the constraints.↵↵Optimization completed because the objective function is non-decreasing in ↵feasible directions, to within the value of the optimality tolerance,↵and constraints are satisfied to within the value of the constraint tolerance.↵↵<stopping criteria details>↵↵Optimization completed: The relative first-order optimality measure, 5.707383e-06,↵is less than options.OptimalityTolerance = 1.000000e-05, and the relative maximum constraint↵violation, 0.000000e+00, is less than options.ConstraintTolerance = 1.000000e-03.↵↵'
constrviolation: 0
stepsize: 1.2330e-05
lssteplength: 1
firstorderopt: 5.7074e-06

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by