How can setup optimset for custom data types.

I'm putting xo as initial guess. I want custom data just restricted x0 subset [0,30], by create permutation.
x0 = [30 30 30 30 30 30 0 0 0 0 0 0 0 0 30 30 30 30 30 30];
[x, fval] = fminsearch(@objfun, x0);

댓글 수: 1

Alan Weiss
Alan Weiss 2015년 12월 28일
I am sorry, but I do not understand what you are asking. Your image is from a ga example, but your question seems to be about fminsearch.
So can you please explain what you are trying to do, and what the problem is?
Alan Weiss
MATLAB mathematical toolbox documentation

댓글을 달려면 로그인하십시오.

답변 (1개)

Matt J
Matt J 2015년 12월 28일
편집: Matt J 2015년 12월 28일

0 개 추천

Rewrite the problem in terms of binary variables 0<=y(i)<=1 where y=x/30. Then use the IntCon argument and bound constraints to minimize in terms of y,
N=numberofVariables;
LB=zeros(1,N);
UB=ones(1,N);
IntCon=1:N;
fun=@(y) FitnessFcn(30*y);
x = 30*ga(fun,N,[],[],[],[],LB,UB,IntCon,options);

댓글 수: 4

Matt's solution goes part way there, but it is not able to achieve the "permutations" constraint that you need.
But there is a way in this particular case of permutations of exactly two different values. Use the IntCon just like Matt shows, where (as he shows) a 0 integer input value will be turned into a 0 in the objective function and a 1 integer input value will be turned into a 30 in the objective function. Now to achieve the permutation you need, add a single linear equality constraint:
x0 = [30 30 30 30 30 30 0 0 0 0 0 0 0 0 30 30 30 30 30 30];
N = length(x0);
LB = zeros(1,N);
UB = ones(1,N);
IntCon = 1:N;
Aeq = ones(1,N);
beq = sum(x0 == 30);
x = 30*ga(fun, N, [],[], Aeq, beq, LB,UB, IntCon, options);
where fun is the handle to your objective function that multiplies each of the input values by 30 before use.
The trick I use here is that in order for an input to be a permutation of x0, it must have the same number of 30's as x0 has. Each input will (at the time the constraint is evaluated) be either 0 or 1; multiply that by a vector of 1's and add and the result will be the same as the number of 1's that are in the input; when that number is the same as in x0 then you have an input that satisfies the permutation constraint.
Matt J
Matt J 2015년 12월 29일
편집: Matt J 2015년 12월 29일
Unfortunately, ga doesn't allow you to use IntCon and linear equality constraints simultaneously. Ranjan, are you sure that a permutation of x0 is what you are restricted to instead of all possible combinations of [0,30]? And are you sure the FitnessFcn is nonlinear (otherwise, you should be using intlinprog)?
If so, then Walter's proposal can be rewritten to use only inequality constraints using the variable elimination technique discussed here,
@Walter, I'm sorry...but your code is not running.
Undefined function or variable
'options'.
when i remove options...
Error using ga (line 278)
Fitness function must be a function
handle.
Error using functionHandleOrCell (line
12)
The constraint function must be a
function handle.
Error in validate (line 181)
[nonlcon,NonconFcnArgs] =
functionHandleOrCell('NonconFcn',nonlcon);
Error in gacommon (line 73)
[options,nvars,FitnessFcn,NonconFcn] =
validate(options,type,nvars,fun,nonlcon,user_options);
Error in ga (line 327)
[x,fval,exitFlag,output,population,scores,FitnessFcn,nvars,Aineq,bineq,Aeq,beq,lb,ub,
...
Matt J
Matt J 2016년 1월 20일
편집: Matt J 2016년 1월 20일
You should be wondering why Matlab thinks "options" is undefined, when the code you posted in your question defines it explicitly...
Regardless, Walter's solution will ultimately not work as written because (see My Remark) it tries to use IntCon and linear equalities simultaneously, which ga() does not allow.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Problem-Based Optimization Setup에 대해 자세히 알아보기

태그

질문:

2015년 12월 28일

편집:

2016년 1월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by