Thread Subject: Genetic Algorithm

Subject: Genetic Algorithm

From: Zeinab Ghofrani

Date: 24 Aug, 2006 02:24:03

Message: 1 of 8

Dear freinds

I use ga command.In my case it is to give me a vector of 8 elements
as the answer of genetic algorithm. I want the first 4 elements of
the vector to be a NATURAL number between 0 and 3, I mean 0 or 1 or 2
or 3, but the last 4 elements to be a DOUBLE number between 0 and
1,for example 0.77
How can I do that?

Regards
Zeinab Ghofrani

Subject: Genetic Algorithm

From: helper

Date: 30 Aug, 2006 13:21:22

Message: 2 of 8

Zeinab Ghofrani wrote:
>
>
> Dear freinds
>
> I use ga command.In my case it is to give me a vector of 8 elements
> as the answer of genetic algorithm. I want the first 4 elements of
> the vector to be a NATURAL number between 0 and 3, I mean 0 or 1 or
> 2
> or 3, but the last 4 elements to be a DOUBLE number between 0 and
> 1,for example 0.77
> How can I do that?
>
> Regards
> Zeinab Ghofrani
  
Take a look at this link:

 <http://www.mathworks.com/support/solutions/data/1-10PDHC.html?solution=1-10PDHC>

Subject: Genetic Algorithm

From: Marcus M. Edvall

Date: 31 Aug, 2006 01:43:45

Message: 3 of 8

Hello Zeinad,

glcDirect in the TOMLAB Base Module will fix this for you. Also
TOMLAB /GENO would be possible if using genetic alg.

A lot of times a solver like TOMLAB /MINLP (minlpBB) is a few orders
of magnitude faster. It's good if you have analytical derivatives
then.

Best wishes, Marcus
Tomlab Optimization Inc.
 <http://tomlab.biz>

 Zeinab Ghofrani wrote:
>
>
> Dear freinds
>
> I use ga command.In my case it is to give me a vector of 8 elements
> as the answer of genetic algorithm. I want the first 4 elements of
> the vector to be a NATURAL number between 0 and 3, I mean 0 or 1 or
> 2
> or 3, but the last 4 elements to be a DOUBLE number between 0 and
> 1,for example 0.77
> How can I do that?
>
> Regards
> Zeinab Ghofrani

Subject: Genetic Algorithm

From: Zeinab Ghofrani

Date: 1 Sep, 2006 07:26:27

Message: 4 of 8

Dear helper

Thanks a lot for your company. Now my problem is that the first the
first 4 elements of the vector are not exactly between 2 specific
natural numbers. I want them to be a number from this collection:
33 433 21 22 211 2
What should I do now?

Regards
Zeinab Ghofrani

 helper wrote:
>
>
> Zeinab Ghofrani wrote:
>>
>>
>> Dear freinds
>>
>> I use ga command.In my case it is to give me a vector of 8
> elements
>> as the answer of genetic algorithm. I want the first 4 elements
> of
>> the vector to be a NATURAL number between 0 and 3, I mean 0 or
1
> or
>> 2
>> or 3, but the last 4 elements to be a DOUBLE number between 0
and
>> 1,for example 0.77
>> How can I do that?
>>
>> Regards
>> Zeinab Ghofrani
>
> Take a look at this link:
>
> <http://www.mathworks.com/support/solutions/data/1-10PDHC.html?solution=1-10PDHC>
>

Subject: Genetic Algorithm

From: Dan K

Date: 1 Sep, 2006 06:03:32

Message: 5 of 8


Zeinab Ghofrani wrote:
> Dear helper
>
> Thanks a lot for your company. Now my problem is that the first the
> first 4 elements of the vector are not exactly between 2 specific
> natural numbers. I want them to be a number from this collection:
> 33 433 21 22 211 2
> What should I do now?
The same technique mentioned in the matlab solutions will work here as
well. What I would do is to use the natural numbers again (in this
case between 0 and 5), and then have your fitness function substitue in
the value from the list. i.e. fitness function is given input=[2 1 3
4 0.0001 0.333 0.12 0.6] and calculates fitness on a second vector
constructed from that by:

valueList=[33 433 21 22 211 2];
actualVector=[valueList(input(1:4)), input(5:8)];


and carry on.

Then when you get your final answer repeat the process:

actualSolution=[valueList(returnedValues(1:4)), returnedValues(5:8)];

HTH
>
> Regards
> Zeinab Ghofrani
>
> helper wrote:
> >
> >
> > Zeinab Ghofrani wrote:
> >>
> >>
> >> Dear freinds
> >>
> >> I use ga command.In my case it is to give me a vector of 8
> > elements
> >> as the answer of genetic algorithm. I want the first 4 elements
> > of
> >> the vector to be a NATURAL number between 0 and 3, I mean 0 or
> 1
> > or
> >> 2
> >> or 3, but the last 4 elements to be a DOUBLE number between 0
> and
> >> 1,for example 0.77
> >> How can I do that?
> >>
> >> Regards
> >> Zeinab Ghofrani
> >
> > Take a look at this link:
> >
> > <http://www.mathworks.com/support/solutions/data/1-10PDHC.html?solution=1-10PDHC>
> >

Subject: Genetic Algorithm

From: Zeinab Ghofrani

Date: 2 Sep, 2006 03:38:57

Message: 6 of 8

Dear Dan

Thanks a lot for your answer. However I wonder if this solution is a
good one from Genetic Algorithm point of view.Of course it WILL give
an answer, but won't it confuse Genetic algorithm how to find a
better answer?

Thanks again
Zeinab Ghofrani

 Dan K wrote:
>
>
>
> Zeinab Ghofrani wrote:
>> Dear helper
>>
>> Thanks a lot for your company. Now my problem is that the first
> the
>> first 4 elements of the vector are not exactly between 2
specific
>> natural numbers. I want them to be a number from this
collection:
>> 33 433 21 22 211 2
>> What should I do now?
> The same technique mentioned in the matlab solutions will work here
> as
> well. What I would do is to use the natural numbers again (in
> this
> case between 0 and 5), and then have your fitness function
> substitue in
> the value from the list. i.e. fitness function is given input=[2
> 1 3
> 4 0.0001 0.333 0.12 0.6] and calculates fitness on a second vector
> constructed from that by:
>
> valueList=[33 433 21 22 211 2];
> actualVector=[valueList(input(1:4)), input(5:8)];
>
>
> and carry on.
>
> Then when you get your final answer repeat the process:
>
> actualSolution=[valueList(returnedValues(1:4)),
> returnedValues(5:8)];
>
> HTH
>>
>> Regards
>> Zeinab Ghofrani
>>
>> helper wrote:
>> >
>> >
>> > Zeinab Ghofrani wrote:
>> >>
>> >>
>> >> Dear freinds
>> >>
>> >> I use ga command.In my case it is to give me a vector
of 8
>> > elements
>> >> as the answer of genetic algorithm. I want the first 4
> elements
>> > of
>> >> the vector to be a NATURAL number between 0 and 3, I
mean 0 or
>> 1
>> > or
>> >> 2
>> >> or 3, but the last 4 elements to be a DOUBLE number
between 0
>> and
>> >> 1,for example 0.77
>> >> How can I do that?
>> >>
>> >> Regards
>> >> Zeinab Ghofrani
>> >
>> > Take a look at this link:
>> >
>> > <http://www.mathworks.com/support/solutions/data/1-10PDHC.html?solution=1-10PDHC>
>> >
>
>

Subject: Genetic Algorithm

From: Dan K

Date: 5 Sep, 2006 05:41:40

Message: 7 of 8

Zeinab:
Bear in mind that the genetic algorithm isn't trying new solutions
based on the rate of improvment from prior solutions. Every mutation
or combination is inherently random. Because the whole principle is in
trying enough combinations that the good ones eventually sort their way
to the top, you cannot confuse it. The primary risk in a GA problem is
if the desirable solution is extremely narrow (that is, you don't see
any improvement until you are pretty much right on top of the right
answer). In cases like that I have found it very useful to create
specialized fitness functions to help steer me in the right direction.


One thing that I have found to be absolutely key in cases like that is
that if I am trying to optimize a double, DON'T apply a penalty like:
if x>100
error=error+10; % This adds a step to the error function
end

Since the GA really has no idea how to get from the bad zone (>100) to
the good zone. Also, since it is usually set up with the mutations
being small, if it ends up with x=1000 the odds of mutating into the
good zone are very small. Instead I try to modify it so that even a
small step in the right direction is rewareded:

if x>100
error=error+(x-100); % This adds a linear slop to the error function.
end

BTW I don't recommend expressions that overwrite themselves. It was
just more clear in this case. Also, one warning about this approach:
If you use several of them at once, you need to be very sure that there
isn't any hidden interactions between the various conditions; I once
spent about a week chasing one of those!

HTH

Dan


Zeinab Ghofrani wrote:
> Dear Dan
>
> Thanks a lot for your answer. However I wonder if this solution is a
> good one from Genetic Algorithm point of view.Of course it WILL give
> an answer, but won't it confuse Genetic algorithm how to find a
> better answer?
>
> Thanks again
> Zeinab Ghofrani
>
> Dan K wrote:
> >
> >
> >
> > Zeinab Ghofrani wrote:
> >> Dear helper
> >>
> >> Thanks a lot for your company. Now my problem is that the first
> > the
> >> first 4 elements of the vector are not exactly between 2
> specific
> >> natural numbers. I want them to be a number from this
> collection:
> >> 33 433 21 22 211 2
> >> What should I do now?
> > The same technique mentioned in the matlab solutions will work here
> > as
> > well. What I would do is to use the natural numbers again (in
> > this
> > case between 0 and 5), and then have your fitness function
> > substitue in
> > the value from the list. i.e. fitness function is given input=[2
> > 1 3
> > 4 0.0001 0.333 0.12 0.6] and calculates fitness on a second vector
> > constructed from that by:
> >
> > valueList=[33 433 21 22 211 2];
> > actualVector=[valueList(input(1:4)), input(5:8)];
> >
> >
> > and carry on.
> >
> > Then when you get your final answer repeat the process:
> >
> > actualSolution=[valueList(returnedValues(1:4)),
> > returnedValues(5:8)];
> >
> > HTH
> >>
> >> Regards
> >> Zeinab Ghofrani
> >>
> >> helper wrote:
> >> >
> >> >
> >> > Zeinab Ghofrani wrote:
> >> >>
> >> >>
> >> >> Dear freinds
> >> >>
> >> >> I use ga command.In my case it is to give me a vector
> of 8
> >> > elements
> >> >> as the answer of genetic algorithm. I want the first 4
> > elements
> >> > of
> >> >> the vector to be a NATURAL number between 0 and 3, I
> mean 0 or
> >> 1
> >> > or
> >> >> 2
> >> >> or 3, but the last 4 elements to be a DOUBLE number
> between 0
> >> and
> >> >> 1,for example 0.77
> >> >> How can I do that?
> >> >>
> >> >> Regards
> >> >> Zeinab Ghofrani
> >> >
> >> > Take a look at this link:
> >> >
> >> > <http://www.mathworks.com/support/solutions/data/1-10PDHC.html?solution=1-10PDHC>
> >> >
> >
> >

Subject: Genetic Algorithm

From: Zeinab Ghofrani

Date: 10 Sep, 2006 08:46:13

Message: 8 of 8

Dear friends

The answers of ga in my case is a matrix with natural elements. I
used the solution in the address below:

 <http://www.mathworks.com/support/solutions/data/1-10PDHC.html?solution=1-10PDHC>>
 
Now my problem is that the 1st and 2nd elements of the ga answer
should be A NATURAL NUMBER betweetn 1 and 3 but SHOULDN'T BE EQUAL.
How can I fulfill this?

Regards
Zeinab Ghofrani

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com