Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Genetic algorithms, gamultiobj

Subject: Genetic algorithms, gamultiobj

From: Sergen Yalcin

Date: 1 Mar, 2009 00:24:01

Message: 1 of 5

Hello,
I am using "gamultiobj" function in Genetic algorithms toolbox. I am trying to optimize to objective functions. My m-file is as following:

function f = fitness(x)

w=logspace(-2,2,100);
f = zeros(size(w,2),2); % f has dimension 100x2

C=[x(1) x(2) x(3) x(4) x(5)];
Hk=freqrespFr(C,1,w); % My own function
H=Hk'; % H has dimension 100x1

P=tf(1,[1 1]);
Gk=freqresp(P,w);
G=squeeze(Gk); % G has dimension 100x1

f(:,1)=abs(1./(1+H.*G)); % first fitness function
f(:,2)=abs((H.*G)./(1+(H.*G))); % second fitness function

When I run this function in Genetic algorithms gui, I get error message:
Subscripted assignment dimension mismatch.

I have checked the dimension of all parameters and all seems to be correct. When I tried all commands in this m-file in Command window, it works and return correct values for f(:,1) and f(:,2).

What is wrong? Can you please help me?

Thanks:)

Subject: Genetic algorithms, gamultiobj

From: Alan Weiss

Date: 2 Mar, 2009 14:30:30

Message: 2 of 5

Hi, Sergen. I believe that you are trying to compute your fitness
functions in a vectorized fashion, a commendable programming practice.
The error might be caused by failing to inform gamultiobj that you want
to have vectorized function evaluations. If you haven't already, try setting
options = gaoptimset('Vectorized','On');
and call gamultiobj with the options structure.

Alan Weiss
MATLAB mathematical toolbox documentation

Sergen Yalcin wrote:
> Hello,
> I am using "gamultiobj" function in Genetic algorithms toolbox. I am trying to optimize to objective functions. My m-file is as following:
>
> function f = fitness(x)
>
> w=logspace(-2,2,100);
> f = zeros(size(w,2),2); % f has dimension 100x2
>
> C=[x(1) x(2) x(3) x(4) x(5)];
> Hk=freqrespFr(C,1,w); % My own function
> H=Hk'; % H has dimension 100x1
>
> P=tf(1,[1 1]);
> Gk=freqresp(P,w);
> G=squeeze(Gk); % G has dimension 100x1
>
> f(:,1)=abs(1./(1+H.*G)); % first fitness function
> f(:,2)=abs((H.*G)./(1+(H.*G))); % second fitness function
>
> When I run this function in Genetic algorithms gui, I get error message:
> Subscripted assignment dimension mismatch.
>
> I have checked the dimension of all parameters and all seems to be correct. When I tried all commands in this m-file in Command window, it works and return correct values for f(:,1) and f(:,2).
>
> What is wrong? Can you please help me?
>
> Thanks:)

Subject: Genetic algorithms, gamultiobj

From: Sergen Yalcin

Date: 2 Mar, 2009 17:20:17

Message: 3 of 5

Hi, Alan. Thank you for response. I think you are misunderstanding me. I know already about "vectorized" function and it is a good method to make gamultiobj faster.

My problem is as following:
I have 2 fitness functions i want to minimize.
The input x has a size of 1x5, (5 independent variables)
The output has a size of 2x200, where each row represent the values of one fitness function after one iteration.

But I think the error causes by wrong options. Because I send the output (2x200) to gamultiobj without adjusting the population size or other options. I try with different values, but i still get same error.

Which options may I have when I have the input and output which are mentioned above?


Alan Weiss <aweiss@mathworks.com> wrote in message <gogqi6$ko8$1@fred.mathworks.com>...
> Hi, Sergen. I believe that you are trying to compute your fitness
> functions in a vectorized fashion, a commendable programming practice.
> The error might be caused by failing to inform gamultiobj that you want
> to have vectorized function evaluations. If you haven't already, try setting
> options = gaoptimset('Vectorized','On');
> and call gamultiobj with the options structure.
>
> Alan Weiss
> MATLAB mathematical toolbox documentation

Subject: Genetic algorithms, gamultiobj

From: Alan Weiss

Date: 2 Mar, 2009 21:22:05

Message: 4 of 5

Sorry, I didn't read your description carefully enough before. You are
stating that your fitness function is 100- or 200-dimensional? And you
have two fitness functions?

Perhaps there is some misunderstanding here. Fitness functions are
supposed to be one-dimensional. If you have a 100-dimensional fitness
function, well, I think that is 100 1-dimensional fitness functions. You
have a 5-dimensional decision variable, and I think you have 200 fitness
functions. According to the gamultiobj function reference page, your
fitness function is supposed to be a 1-by-numberOfObjectives vector, not
a 2-by-something matrix.

But maybe I am still misunderstanding you. Do you really want to
minimize every component of your 200-vector (equivalently, of your
2-by-100 matrix)? So every x that minimizes at least one of the 200
components will be considered good (a Pareto solution)? Or do you mean
something else?

Alan Weiss
MATLAB mathematical toolbox documentation

Sergen Yalcin wrote:
> Hi, Alan. Thank you for response. I think you are misunderstanding me. I know already about "vectorized" function and it is a good method to make gamultiobj faster.
>
> My problem is as following:
> I have 2 fitness functions i want to minimize.
> The input x has a size of 1x5, (5 independent variables)
> The output has a size of 2x200, where each row represent the values of one fitness function after one iteration.
>
> But I think the error causes by wrong options. Because I send the output (2x200) to gamultiobj without adjusting the population size or other options. I try with different values, but i still get same error.
>
> Which options may I have when I have the input and output which are mentioned above?
>
>
> Alan Weiss <aweiss@mathworks.com> wrote in message <gogqi6$ko8$1@fred.mathworks.com>...
>> Hi, Sergen. I believe that you are trying to compute your fitness
>> functions in a vectorized fashion, a commendable programming practice.
>> The error might be caused by failing to inform gamultiobj that you want
>> to have vectorized function evaluations. If you haven't already, try setting
>> options = gaoptimset('Vectorized','On');
>> and call gamultiobj with the options structure.
>>
>> Alan Weiss
>> MATLAB mathematical toolbox documentation

Subject: Genetic algorithms, gamultiobj

From: Sergen Yalcin

Date: 3 Mar, 2009 18:00:21

Message: 5 of 5

Hi,

I have solved this problem. You are right, I can't use a multi-dimensional valued fitness function. So sorry for confusing you.

Thanks

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us