|
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>
> >> >
> >
> >
|