How do I get the winning program "out" once I'm done?

114 views
Skip to first unread message

Ian Clarke

unread,
Jun 2, 2011, 6:50:25 PM6/2/11
to epo...@googlegroups.com
How do I obtain the winning program (using the GPModel) at the end of my evolutionary cycles?

Can the program be serialized to be loaded in later and used for something, or fed back in to the first generation of a new evolutionary process?

Sorry if these are dumb questions, but I haven't been able to find answers in the documentation.

Ian.


--
Ian Clarke

Tom Castle

unread,
Jun 2, 2011, 8:42:05 PM6/2/11
to EpochX
You can use the stats system. The best program found so far at any
point, can be retrieved with the StatField.RUN_FITTEST_PROGRAM stat
and its fitness will be StatField.RUN_FITNESS_MIN.

GPCandidateProgram best = (GPCandidateProgram)
Stats.get().getStat(StatField.RUN_FITTEST_PROGRAM);
double fitness = (Double)
Stats.get().getStat(StatField.RUN_FITNESS_MIN);

More information about stats is available here: http://www.epochx.org/guide-statistics.php

Given the GPCandidateProgram instance you could certainly hold onto it
and insert it into a generation of a following run. There is no direct
way of serializing a program. But one way of achieving this would be
to get its string (source) representation, which the EpoxParser class
should in theory be able to parse back into a node tree. Although I
suspect you would have to extend EpoxParser and override the
parseLiteral(String) method, to ensure it could parse your new literal
types correctly.

Tom

Ian Clarke

unread,
Jun 3, 2011, 9:11:43 AM6/3/11
to epo...@googlegroups.com
Ah, ok, thank you once again.

Is there any reason that GPCandidateProgram couldn't implement the Serializable interface?

Ian.

Tom Castle

unread,
Jun 5, 2011, 7:07:11 AM6/5/11
to EpochX
No reason at all, and it probably should!

Tom

Ian Clarke

unread,
Jun 6, 2011, 5:59:40 PM6/6/11
to epo...@googlegroups.com
Hi Tom,

Hmm, the inability to serialize a winning GPCandidateProgram is proving to be a considerable problem for me, as it basically means that I need to evolve a program from scratch every time, which, when this takes several hours, isn't really practical.

Can you elaborate a little on how I extend EpoxParser to parse the string representation of programs?  It doesn't sound like you are all that confident that EpoxParser will be a good solution for this.

Can you think of any reliable way to serialize one of these programs - or alternatively patch EpochX such that GPCandidateProgram implements Serializable?

Sorry to be a pest.

Ian.

Ian Clarke

unread,
Jun 6, 2011, 7:30:59 PM6/6/11
to epo...@googlegroups.com
Just to elaborate, I have a new Literal type that represents a random double between 0 and 1 (some of my Nodes require an input double in this range).

But there is no way for the parser to determine that this is this special kind of double rather than a normal double, except through its context (as the parser appears to be context-free).

Am I misunderstanding something?

Ian.

Ian Clarke

unread,
Jun 7, 2011, 8:13:09 AM6/7/11
to epo...@googlegroups.com
Ok, things went better than expected with EpoxParser, and it appears to work.  I had to find a new recognizable way to identify the 0-1 literals, so I just prefix the double with an 'i'.

I would definitely recommend, if you aren't already planning it in the next version, to make it easier to serialize GPCandidatePrograms if at all possible, perhaps by making them implement Serializable, and making the requisite changes such that this works.

One issue seems to be that some Node types require stuff to be injected from the Model on construction, such as how the various ERC Literals require a RandomNumberGenerator.  I haven't quite got a good solution for this yet, so for now I just parse them as ordinary Literals (but I'm injecting a one of my Models in to the constructor of subclass of EpoxParser, so I guess I could get the RNG from that).

Ian.

Tom Castle

unread,
Jun 8, 2011, 6:45:46 AM6/8/11
to EpochX
We'll definitely take a look at serialization for future versions.
There's already plans to provide a way of pausing/re-starting runs,
which will require saving the state of the population so I suspect
this will be solved at the same time.

Glad you managed to get the EpoxParser working. I was confident it
should work in theory, but less confident that it would in practice :)

Are you sure you need to differentiate between literals that were
generated randomly, and other types of literal. Because presumably the
randomisation only takes place when the node is constructed (at
initialisation or mutation), but from then on, it just behaves like
any other literal? If that's not the case, then the programs being
evolved would be non-deterministic, which is probably not a good idea
in most cases. This would also solve the problem with supplying the
reconstructed literal with an RNG, if it doesn't actually need to
perform any further random behaviour.

Tom

Ian Clarke

unread,
Jun 8, 2011, 11:37:23 AM6/8/11
to epo...@googlegroups.com
On Wed, Jun 8, 2011 at 5:45 AM, Tom Castle <tc...@kent.ac.uk> wrote:
Are you sure you need to differentiate between literals that were
generated randomly, and other types of literal. Because presumably the
randomisation only takes place when the node is constructed (at
initialisation or mutation), but from then on, it just behaves like
any other literal? If that's not the case, then the programs being
evolved would be non-deterministic, which is probably not a good idea
in most cases. This would also solve the problem with supplying the
reconstructed literal with an RNG, if it doesn't actually need to
perform any further random behaviour.

I wasn't sure how it worked internally, eg. if the xxxERC nodes are expected to "self-mutate".  But  if not, then yes - I can just turn them into normal Literals (which is how I'm doing it).

Cheers!

Ian.

--
Ian Clarke
CEO, SenseArray
Email: i...@sensearray.com
Ph: +1 512 422 3588

Ian Clarke

unread,
Jun 8, 2011, 12:30:01 PM6/8/11
to epo...@googlegroups.com
On Thursday, June 2, 2011 7:42:05 PM UTC-5, Tom Castle wrote:
Given the GPCandidateProgram instance you could certainly hold onto it
and insert it into a generation of a following run. 

What would be the best way to achieve this?  ie. which hook should I use?

Ian. 

Tom Castle

unread,
Jun 8, 2011, 1:01:56 PM6/8/11
to EpochX
It is probably either the initialisation or generation hook that you
want, depending on whether you intend to insert the program(s) from
the beginning of an evolutionary run, or after a number of
generations. You can just add your stored programs to the population
list that the hook receives before returning it.

Ian Clarke

unread,
Jun 9, 2011, 1:57:26 PM6/9/11
to epo...@googlegroups.com
Thanks Tom, I went with initialisationHook().

Ian.
Reply all
Reply to author
Forward
0 new messages