0

I am trying to implement the fmincon function in MATLAB. I am getting a warning with an algorithm change to evaluate my function (warning shown at the end of post). I wanted to use fminsearch, but I have 2 constraints I need to follow. It doesn't make sense for MATLAB to change algorithms to evaluate my function because my constraints are very simple. I have provided the constraint and piece of code:

Constraints:
theta(0) + theta(1) < 1

theta(0), theta(1), theta(2), theta(3) > 0

% Solve MLE using fmincon
ret_1000 = returns(1:1000);
A = [1 1 0 0];
b = [.99999];
lb = [0; 0; 0; 0];
ub = [1; 1; 1; 1];
Aeq = [];
beq = [];
noncoln = [];
init_guess = [.2;.5; long_term_sigma; initial_sigma];
%option = optimset('FunValCheck', 1000);
options = optimset('fmincon');
options = optimset(options, 'MaxFunEvals', 10000);
[x, maxim] = fmincon(@(theta)Log_likeli(theta, ret_1000), init_guess, A, b, Aeq, beq, lb, ub, noncoln, options);

Warning:

Warning: The default trust-region-reflective algorithm does not solve problems with the constraints you
have specified. FMINCON will use the active-set algorithm instead. For information on applicable
algorithms, see Choosing the Algorithm in the documentation. 
> In fmincon at 486
  In GARCH_loglikeli at 30 

Local minimum possible. Constraints satisfied.

fmincon stopped because the predicted change in the objective function
is less than the selected value of the function tolerance and constraints 
are satisfied to within the selected value of the constraint tolerance.

<stopping criteria details>

No active inequalities.
Josh
  • 3,231
  • 8
  • 37
  • 58
  • Your options seem ok. What is the type of the arrays `A` and `lb`. Is it uint8? It should be double. This stands also for your `ret_1000` array. – sfotiadis Mar 07 '13 at 13:57
  • How can I tell if they are unit8 or double? And how can I change them to a double? – Josh Mar 07 '13 at 14:17
  • I changed my post to reflect, what I think you meant. – Josh Mar 07 '13 at 14:29
  • 1
    This is actually not a problem, just a warning. You can explicitly set `options = optimset(options, 'MaxFunEvals', 10000, 'Algorithm', 'active-set')` to avoid it. – sfotiadis Mar 07 '13 at 16:48

1 Answers1

0

All matlab variables are double my default. You can force a double using, double(variableName), you can get the type of a variable using class(variableName). I would use the class on all your variables to make sure they are what you expect. I don't have fmincon, but I tried a variant of your code on fminsearch and it worked like a charm:

op = optimset('fminsearch');
op = optimset(op,'MaxFunEvals',1000,'MaxIter',1000);
a = sqrt(2);
banana = @(x)100*(x(2)-x(1)^2)^2+(a-x(1))^2;
[x,fval] = fminsearch(banana, [-1.2, 1],op)

Looking at the matlab documentation, I think your input variables are not correct:

x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options)

I think you need:

% Let's be ultra specific to solve this syntax issue

fun = @(theta) Log_likeli(theta, ret_1000);
x0 = init_guess;
% A is defined as A
% b is defined as b
Aeq = [];
beq = [];
% lb is defined as lb
% ub is not defined, not sure if that's going to be an issue
% with the solver having lower, but not upper bounds probably isn't
% but thought it was worth a mention
ub = [];
nonlcon = [];
% options is defined as options
x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options)
macduff
  • 4,655
  • 18
  • 29
  • My constraints are theta(1) + theta(2) < 1 AND theta(0), theta(1), theta(2), theta(3) are all greater than 0. I defined my A vector with reflect the first constraint and lb for the second – Josh Mar 07 '13 at 15:29
  • @Josh, ok, great! But in your question your call to `fmincon` has the input variables in the wrong order, i.e. missing `nonlcon` and `ub`. – macduff Mar 07 '13 at 15:50
  • Hey I just changed the my code around, I have updated my post to reflect the changes. – Josh Mar 07 '13 at 15:53
  • I'm getting a warning message, where I still might be inputting my constraints incorrectly – Josh Mar 07 '13 at 15:56
  • Also, I can't use fminsearch because it doesn't take the constraints into account – Josh Mar 07 '13 at 16:29