Fmincon optimization of integral with nonlinear constraints leads to false result
2 views (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
Alan Weiss
on 12 Feb 2018
Edited: Alan Weiss
on 12 Feb 2018
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
0 Comments
More Answers (1)
Walter Roberson
on 10 Feb 2018
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 Comments
See Also
Categories
Find more on Nonlinear Optimization 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!