My fitness function (fit_KotPol) calculate two values for 24 variables. I want to define the inti
fitnessfcn = @fit_KotPol;
nvars = 24;
lb=[22.2 22.2 22.2 22.2 22.2 22.2 22.2 22.2 22.2 22.2 22.2 22.2 0 0 0 0 0 0 0 0 0 0 0 0];
ub=[172.9 172.9 172.9 172.9 172.9 172.9 172.9 172.9 172.9 172.9 172.9 172.9 140 140 140 140 140 140 140 140 140 140 140 140];
A = [ ]; b = [ ]; Aeq = [ ]; beq = [ ];
startTime = tic;
options = optimoptions('gamultiobj','UseParallel',true,'PlotFcn',{@gaplotpareto,@gaplotscorediversity});
[x,fval,exitflag,output] = gamultiobj(fitnessfcn,nvars,lb,ub,options);
stopTime = toc(startTime);
I got the error
Error using gamultiobj (line 281)
GAMULTIOBJ requires the following inputs to be of data type double: 'Aeq'.
Help me to use the gamultiobj

답변 (2개)

Stephan
Stephan 2018년 9월 23일
편집: Stephan 2018년 9월 23일

0 개 추천

Hi,
the input syntax for gamultiobj has no option for passing lb and ub to gamultiobj without also passing A,b Aeq, beq. You defined them all, but you dont use them in your function call.
Use:
[x,fval,exitflag,output] = gamultiobj(fitnessfcn,nvars,A,b,Aeq,beq,lb,ub,options);
Best regards
Stephan

댓글 수: 16

Thushara De Silva
Thushara De Silva 2018년 9월 24일
Hi Stephan thank you for the reply. One following question for the same problem. I can't see the pareto plot and blank graph is appeared with the message "gaplotpareto not supported for this algorithm". Can you pl explain. Thanks.
Stephan
Stephan 2018년 9월 24일
편집: Stephan 2018년 9월 24일
I would expect this to work:
options = optimoptions(@gamultiobj,'UseParallel',true,'PlotFcn',{@gaplotpareto,@gaplotscorediversity});
Thushara De Silva
Thushara De Silva 2018년 9월 27일
I used the same as shown above, but didn't work. I think the problem is with defining my objectives. It is as follows.
function [A, B] = fit_KotPol( x )
function name: fit_KotPol calculate the two objectives (A and B) using xi (24 vars). So I have defined fitnessfcn = @fit_KotPol; nvars = 24;
From the above codes what I got one set of x values and one value for objective. What I want to have an array of 2 obtectives as points at Pareto plot and corresponding x values (sets of 24 values). Please help me to revise the code.
Stephan
Stephan 2018년 9월 27일
Can you attach the code you have tried so far?
Thushara De Silva
Thushara De Silva 2018년 9월 27일
편집: Walter Roberson 2018년 9월 28일
function [A, B] = fit_KotPol( x )
...several calculations
A=
B=
end
The above function (fit_KotPol(x)) is for calculating the A and B, which are the values for two objectives for each set x values.
fitnessfcn = @fit_KotPol;
nvars = 24;
lb=[22.2 22.2 22.2 22.2 22.2 22.2 22.2 22.2 22.2 22.2 22.2 22.2 0 0 0 0 0 0 0 0 0 0 0 0];
ub=[172.9 172.9 172.9 172.9 172.9 172.9 172.9 172.9 172.9 172.9 172.9 172.9 140 140 140 140 140 140 140 140 140 140 140 140];
A = [ ]; b = [ ];
Aeq = [ ]; beq = [ ];
startTime = tic;
options = optimoptions('gamultiobj','UseParallel',true,'PlotFcn',{@gaplotpareto,@gaplotscorediversity});
[x,fval,exitflag,output] = gamultiobj(fitnessfcn,nvars,A,b,Aeq,beq,lb,ub,options);
stopTime = toc(startTime);
fprintf('The number of points on the Pareto front was: %d\n', size(x,1));
fprintf('The average distance measure of the solutions on the Pareto front was: %g\n', Output.averagedistance);
fprintf('The spread measure of the Pareto front was: %g\n', Output.spread);
fprintf('The number of generations was : %d\n', Output.generations);
Stephan
Stephan 2018년 9월 27일
편집: Stephan 2018년 9월 27일
You could try:
function A = fit_KotPol(x)
...several calculations
A(1) = A;
A(2) = B;
end
Since this is a difference to the examples given in the documentation. The objectives in documentation are stored in one vector. I could imagine that this is the problem.
Thushara De Silva
Thushara De Silva 2018년 9월 27일
thank you for the reply. This optimization runs for 3 days, although I use parallel operation. Do you know any other method to increase the speed of optimization. Also please tell me how to measure the optimization time. I got value for start time as 69686032139 and stop time as 300833.162771188 from the previous run. I cannot figure out what those values mean.
parallel does not have to be fast. I recommend you to vectorize the function. then you can choose the option
'UseVectorized',true
instead of parallel.
Thushara De Silva
Thushara De Silva 2018년 9월 28일
I read the documents of UseVectorized. I don't how to write indexing of vaiable when calling a function for optimization. variables x is 24 long array (24 vars) and population size =200. please help.
function [obj] = fit_KotPol( x)
P = x(:,1:12); Q =x(:,13:24);
This code bring the error "When 'Vectorized' is 'on', your fitness function must return a vector of length equal to the size of the population."
Stephan
Stephan 2018년 9월 28일
Can you attach the code of your function?
Thushara De Silva
Thushara De Silva 2018년 9월 28일
편집: Walter Roberson 2018년 9월 28일
fitnessfcn = @ fit_KotPol;
nvars = 24;
options = optimoptions('gamultiobj','UseVectorized',true,'PopulationSize',200,'InitialPopulationMatrix',Initial,'PlotFcn',{@gaplotpareto,@gaplotscorediversity});
[x,fval,exitflag,output,population,scores] = gamultiobj(fitnessfcn,nvars,A,b,Aeq,beq,lb,ub,options);
function [obj] = fit_KotPol(x)
P = x(:,1:12); Q =x(:,13:24);
...several steps for calculation
obj(1) =
obj(2) =
Thushara De Silva
Thushara De Silva 2018년 9월 28일
편집: Walter Roberson 2018년 9월 28일
further to above, there are two for loops inside the function (fit_KotPol). Actually codes for the function are 500 lines.
for j=1:1000
for 1=1:12
end
end
obj(1)=
obj(2)=
Stephan
Stephan 2018년 9월 28일
How often does your code run? Is it worth revising the code, or is it better to wait 3 days for the calculation to finish, because the code is only used a few times?
Thushara De Silva
Thushara De Silva 2018년 9월 28일
편집: Walter Roberson 2018년 9월 28일
yes. you are right, it is few times. So better to wait 3 days. One last question, before I start the new model run. From the below code can I get the set of solution (values) for variables (24 x n) for n Pareto points. For 200 population, 100 generation what is the n?
[x,fval,exitflag,output,population,scores] = gamultiobj(fitnessfcn,nvars,A,b,Aeq,beq,lb,ub,options);
Walter Roberson
Walter Roberson 2018년 9월 28일
The number of pareto points returned by gamultiobj is not known in advance.
x will be m by nvars, so something by 24 in your case, where m is however many pareto points the function detected during the limits it was given on execution.
Thushara De Silva
Thushara De Silva 2018년 9월 28일
Thank you Walter Roberson and Stephan Jung for the reply. Those are really helpful.

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

Thushara De Silva
Thushara De Silva 2018년 9월 27일
편집: Walter Roberson 2018년 9월 28일

0 개 추천

Further to the above question how can I initialize the population? I want to give initial values for 24 variables as below.
InitialPopulationMatrix_Data = [93.2 66.6 40 59 78 97 116 135 154 172.9 146.3 119 39 76 104 120 107 58 80 80 53 61 60 36]
However, the population size is 200 as default. How do I do it?
Please help.

댓글 수: 1

Walter Roberson
Walter Roberson 2018년 9월 28일
When you supply a population matrix in the options, if the number of rows you provide is less than the population size, then it will initialize the remaining rows randomly.

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

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2018년 9월 23일

댓글:

2018년 9월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by