(yet) another question: Simplifying programs

23 views
Skip to first unread message

Ian Clarke

unread,
Jun 2, 2011, 7:16:38 PM6/2/11
to epo...@googlegroups.com
I notice that a lot of my programs could be simplified, where I see things like GT(0.5, 0.6) which of course could be replaced by False, or similar redundant operations with mathematical operators.

Hook.generationHook() looks like it might be the right place to do this, is this correct?

How would I go about traversing a GPCandidateProgram to prune redundant code, such as the examples above?  I realize that I'll need to create specific rules for the various different Node types.

Ian.


--
Ian Clarke

Tom Castle

unread,
Jun 2, 2011, 9:06:46 PM6/2/11
to EpochX
Yes, if you wanted to perform pruning after each generation then hooks
would be a good way to do this. Something along these lines should
work:

Life.get().addHook(new AbstractHook() {
public List<CandidateProgram> generationHook(List<CandidateProgram>
pop) {
for (CandidateProgram p: pop) {
prune(p);
}

return pop;
}
});

Sometimes it is actually preferable to leave the junk code in though,
because it can provide material for the genetic operators to work
with, and recombine in different configurations. This is probably
problem dependent. Of course you would still probably want to
simplifying the final solutions found though.

To traverse the program tree, get the root node for the
GPCandidateProgram with the getRootNode() method, and then use the
methods available on the Node to get/set its child nodes.

Tom

Ian Clarke

unread,
Jun 3, 2011, 9:17:57 AM6/3/11
to epo...@googlegroups.com
Yes, you are probably right, this would be a premature optimization.

I do impose a very small penalty for longer programs, and over time this seems fairly effective at pruning them down.

Ian.
Reply all
Reply to author
Forward
0 new messages