Re: Optimization problem
- From: Alan Weiss <aweiss@xxxxxxxxxxxxx>
- Date: Mon, 06 Apr 2009 08:46:06 -0400
Sorry, I typed a bit too fast. In point 3 I meant zeros(8,1) and ones(8,1)/4
Alan Weiss wrote:
Phil, I don't have time right now to consider your problem in depth, but I see several errors in your solution attempt..
1. You set your tolerances so tight that fmincon can never end. I suggest you start with the default tolerances, then gradually tighten them, perhaps by a factor of 2 to 10 smaller each time, until you obtain something satisfactory. Having TolFun and TolX set to 1e-20 makes no sense, and having TolCon = 1e-30 is absurd, too.
2. Try setting Algorithm to 'interior-point' and don't use the LargeScale option (unless you are running an older version of MATLAB; the interior-point algorithm was introduced in R2008a). You cannot use the LargeScale algorithm (now called trust-region-reflective) in any case because you are not supplying derivatives, and because the algorithm does not handle both bound and linear constraints simultaneously.
3. Your values of lb and ub should be zeros(8,0) and ones(8,0)/4, not scalars.
4. Don't put the computation of cov(Data) inside an evaluation of c, do it outside that computation (you're wasting a great deal of time recomputing the same thing again and again). So see how to pass an extra parameter such as cov(Data), look at
http://www.mathworks.com/access/helpdesk/help/toolbox/optim/ug/brhkghv-7.html
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
finance.analyse@xxxxxxxxx wrote:I have a unusual problem to solve with Matlab and I'm afraid I can't
find anything logical.
I have a Polynomial Goal Programming (PGP, done by Davies, Kat & Lu in
2004) problem and don't really know how to treat it. I used fmincon
and had a result. Unfortunately, the result was not respecting 2 out
of 3 of my constraints.
Here is the problem :
Max mean(Data*X) s.t. A*X =1
X'*V*X = 1
0 <= X(i) <= 0.25
where Data is (nX8) matrix (created as a GLOBAL variable)
X is (8X1) and represent my weights
A = ones(1,8)
V = cov(Data) that gives us a positive definite (8X8) marix
Here is how I wrote my problem:
%Constraints:
%Weights : 0 =< Xi =< 0.25
lb=0;
ub=0.25;
% Sum Xi = 1
Aeq=ones(1,8);
beq=1;
% optimization settings
optimopt=optimset('fmincon');
optimopt.TolFun=1e-20;
optimopt.TolX=1e-20;
optimopt.MaxIter=40000;
optimopt.MaxFunEvals=150000;
optimopt.Display='final';
optimopt.LargeScale='on';
optimopt.HessUpdate='bfgs';
optimopt.Tolcon=1e-30;
optimopt.Diagnostics='off';
x0=ones(8,1)/8;
[Z1X,fval] = fmincon(@(X) -mean(Data*X),x0,[],
[],Aeq,beq,lb,ub,'nonlcon',optimopt);
I created a nonlcon.m M-file :
function [c ceq]=nonlcon(x)
global Data;
V=cov(Data);
c=0;
ceq=(x'*V*x)-1;
I do receive my weights in Z1X and the minimum of my negative function
(i.e. maximum of my function) in fval. But values in Z1X are between
-70 and 70 (not between 0 and 0.25), X'VX gives me 1,36 (not 1). But
AX gives 1 like asked.
Most parts of this code are cut and paste from previous optimization
problems I made (optimopt per example). Only the nonlcon M-file is the
first time I use such thing and the Matlab Help is not a great ...
help on this ! But when I recheck this code, I do not see anything
catastrophic.
Is there something I am missing ? Should I be using another function ?
Because I remarked that even with 150 000 function evaluations, and a
big 2 minutes running, he is still asking for more MaxFunEval. I
tried a million and still it wasn't enough. And with 6 functions like
this to run ... it will be a complete horror !
Thanks to all
Phil,
HEC Montreal
Financial master degree
- References:
- Optimization problem
- From: finance . analyse
- Re: Optimization problem
- From: Alan Weiss
- Optimization problem
- Prev by Date: Re: Problem with Interrupts using MatLAB/Simulink and Target for
- Next by Date: display gui inside another gui
- Previous by thread: Re: Optimization problem
- Next by thread: Optimization Problem
- Index(es):
Relevant Pages
|
Loading