"solver stopped prematurely" when using fmincon with constraints

3 次查看(过去 30 天)
I am trying to solve a non linear optimization with constraints. It is a simple mean-reversion model, with log-likelihood maximization. It looks likes this: Vector p contains three parameters to be optimized. p(1) = mu, a constant. p(2) = sigma, the standard deviation (so larger than 0). p(3) = alpha, representing mean-reverting behaviour (so between 0 and 1).
p0 = [10 1 0.9];
A = [0 0 1;
0 0 -1
0 -1 0];
b = [ 1;0; 0];
[a fval] = fmincon( @LogLikMeanRev,p0, A,b)
My function LogLikMeanRev is as follows:
function [ f ] = LogLikMeanRev( p )
global y
T = length(y);
x = zeros(T, 1);
LL = 0 ;
for t = 2:T
s = y(t);
f = p(1); % deterministic component, a mean-price level mu
x(t) = s-f; % stochastic component
e = x(t) - x(t-1) + p(3)*x(t-1); % error term = dx + alpha *x_t-1
L = normpdf(e, 0, p(2));
LL = LL + log(L);
end
f=-LL; % -sign because of minimization, and I need maximization
end
This code is after a handbook. The output I get are all "NaN" and the warning is "Solver stopped prematurely. fmincon stopped because it exceeded the function evaluation limit, options.MaxFunEvals = 300 (the default value)."
When I leave the constraints out (that is, optimize with fminsearch), I get a nice response:
a = 0.0079 0.3046 1.1796
However, the third element (alpha), should not exceed 1... hence my attempt to use constraints. Thanks in advance.

采纳的回答

Matt J
Matt J 2014-5-19
编辑:Matt J 2014-5-20
Try using fmincon's sqp algorithm or the interior-point instead of the default. These will enforce lb,ub bounds rigorously (or try to) at all iterations. Accordingly, do not use general linear inequality inputs A,b to specify simple upper & lower bounds. Use the lb,ub inputs instead.
As a more minor remark, it is also not great to use global variables
global y
Follow the guidelines here for using anonymous or nested functions to attach fixed data to a function.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by