laziness, impatience, and hubris PerlMonks

RE: Genetic Programming or breeding Perls

by Crayman (Acolyte)
 on Oct 16, 2000 at 07:01 UTC ( #36864=note: print w/replies, xml ) Need Help??

in reply to Genetic Programming or breeding Perls

```cool concept and the implementation looks well done.
i need to study it more in order to make any detailed

extremely minor nitpiks and some questions.

1)  someone already covered the map in void context.
2)  my \$min = \${\$fitnesses}[0];
for (\$i = 0; \$i < \$size; ++\$i) {
#  set \$i = 1 since you used 0th index to load \$min.
#  same thing for the \$max value in a diff routine later.
\$min = \${\$fitnesses}[\$i] if (\${\$fitnesses}[\$i] < \$min);
}

3)  sub random_gene {
my \$self = shift;
return \${\$self->{GENES}}[rand(@{\$self->{GENES}})];

why do you allow perl to truncate the above, which provides
a fair distribution for the 0th index, but you handle
explicitly below, which never includes the 0th index?  there
may be a good reason, but i couldn't figure out what it was.

if (rand(1.0) < 0.005) {
my \$mutate = 1 + int(rand(@{\$self->{NEW_GENES}} - 1));

4)  if (rand(1.0) > 0.5) {
my \$cut = 1 + int(rand(@genes1 - 1));
# i understand it here - since replacing the entire gene
from beginning might not make sense

5)  i factored out the following from the code so I could stick
everything on the top and play:
my \$Genes = ['\$x+=1 ;', '\$x=\$y ;',  '\$y=\$x ;', '\$x|=\$y ;', '\$x+=\$y ;',
+ ' ;'];
my \$IndivGeneLen = 32;
my \$PopSize = 1999;
my \$Target = 10512;
my \$NumGenerations = 100;

next thought - this can be generalized into a module.
very cool, thanks!
___cliff_AT_rayman.com___

Replies are listed 'Best First'.
RE: RE: Genetic Programming or breeding Perls
by Crayman (Acolyte) on Oct 16, 2000 at 10:12 UTC
i figured out the answer to #3. the declaration of the lexical variables occur in index 0, that makes them position dependent. therefore index 0 has to be skipped during mutations and splicing. something like this might be worthy of a comment in the code. ___cliff rayman___cliff_AT_rayman.com___
RE: RE: Genetic Programming or breeding Perls
by Crayman (Acolyte) on Oct 16, 2000 at 10:13 UTC
```i figured out the answer to #3.  the declaration of the lexical
variables occur in index 0, that makes them position dependent.
therefore index 0 has to be skipped during mutations and splicing.
something like this might be worthy of a comment in the
code.
___cliff rayman___cliff_AT_rayman.com___
```

Create A New User
Node Status?
node history
Node Type: note [id://36864]
help
Chatterbox?
and the grasshoppers chirp...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2017-08-22 21:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Who is your favorite scientist and why?

Results (343 votes). Check out past polls.

Notices?