Fmincon optimization of integral with nonlinear constraints leads to false result

2 次查看(过去 30 天)
I'm trying to optimize the expectation of a log of a sum of random variables. Say, x(:,1:n) = observations of n differently distributed, correlated random variables.
for i = 1:n
temp = temp + c(i+1).*x(:,i);
end
temp = c(1).*temp;
pd = fitdist(temp,'Kernel');
fun = @(x) log(1+x).*pdf(pd,x);
a = integral(fun,-100,10000);
I'm using fmincon to maximize a by finding the optimal vector c. The nonlcon function that I'm using makes sure that:
t = fminsearch(@(x)(cdf(pd,x)-0.05).^2,0);
c = alpha - t;
ceq = 0;
Thus, alpha - t <= 0.
All c elements are constrained to be between 0 and 1 and c(2:n+1) have to sum to 1.
When I use fminsearch with these functions, c(1) is correct, but c(2:n+1) are all roughly the same and that's wrong. Without the nonlinear constraint the script works well and if I replace the integral with a sum over the data points, it works fine with nonlcon as well.
It seems that optimization of an integral is incompatible with nonlinear constraints... What could the problem be? How could I avoid it?

采纳的回答

Alan Weiss
Alan Weiss 2018-2-12
编辑:Alan Weiss 2018-2-12
It is possible that you are running into the issue discussed in Optimizaing a Simulation or ODE, namely, the internally-generated finite difference estimates are noisy. Try setting larger fmincon finite differences, as discussed in the link.
And DO NOT set ceq = 0, set ceq = [] as suggested throughout the documentation. You do not have a nonlinear equality constraint, don't make fmincon tiptoe around trying not to violate the constraint.
Alan Weiss
MATLAB mathematical toolbox documentation

更多回答(1 个)

Walter Roberson
Walter Roberson 2018-2-10
If you are using the nonlcon position, then the function has to return two outputs, typically named c and ceq . However, the relationship between the two is not c <= ceq : the two are independent.
"fmincon optimizes such that c(x) ≤ 0 and ceq(x) = 0."
Your ceq happens to be 0 so in theory that should turn out the same, but I am concerned that you might be misunderstanding the nonlcon output.
  2 个评论
AA
AA 2018-2-10
Thanks for the quick reply! I understand what c and ceq are used for, I just chose to specify ceq = 0, since 0 = 0 is always satisfied. I'm only interested in one constraint.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Nonlinear Optimization 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by