Print

Print


On May 13, 2008, at 2:36 PM, jorge blasco wrote:

> I was wondering if there is some way to test my resulting  
> GPsolutions from training. I would like to use a different file in  
> my evolutioned programs. Is there any solution for this using  
> simply ECJ? I am used to program these tests manually, parsing  
> myself the lisp expression, but now I have like 30 indivuals to  
> test. I have found the ECJ to Java add-on but all individuals have  
> been generated.
>
> I think creating a new individual and calling to eval might be a  
> solution (faking evolution state, etc.). Can this thing be done  
> outside evolution?
>
> Thank you all
>
> Jorge

If you're willing to test them while still in Lisp form, by far the  
easiest way to do it is to write out your individuals to a file and  
then load them into a slightly hacked form of ECJ and do whatever you  
want with them (evaluate them again, for example).

First, you'll need to write your individuals out to a file using  
printIndividual(EvolutionState, PrintWriter) or printIndividual 
(EvolutionState, int log, int verbosity).  These forms allow them to  
be read back in again by ECJ's readIndividual(EvolutionState,  
LineNumberReader) method.  You may wish to flush your writer after  
printing.  Notice that it is NOT printIndividualForHumans(...).

Now let's say you only have one population (no coevolution), and  
you've run 100 times, printing out 100 individuals, and you'd like to  
test them somehow.  I'd do it this way:

0. Concatenate all the individuals into one file.  They need their  
"Evaluated?" and "Fitness:" lines as well as the lines for the  
genotypes.  Cut-and-paste carefully.

1. Create a new EvolutionState object which overrides the evolve()  
method to instead do what you like with the individuals loaded from  
the file.  They'll be loaded into subpopulation 0.  Here's an example  
where we evaluate each of our individuals once again.
	
	package example;
	import ec;
	import ec.simple;

	public class TrivialEvolutionState extends SimpleEvolutionState
		{
		public int evolve()
			{
			SimpleProblemForm prob = (SimpleProblemForm)(p_problem.clone());
         		prob.prepareToEvaluate(this,0);  // for good measure

			Individual[] inds = population.subpops[0].individuals;
			for(int x=0 ; x < inds.length; x++)
				prob.evaluate(this, inds[x], 0, 0);
				// or perhaps prob.describe(this, inds[x], 0, 0);
				// or perhaps you've written some other "special" evaluation method	

			prob.finishEvaluating(this, 0);  // for good measure

			output.message("Great Success!  Hi Five!");
			return R_SUCCESS;
			}
		}

2. Now we need only load the individuals into the population.  We can  
do that by changing a few parameters:

	state = example.TrivialEvolutionState
	init = ec.simple.SimpleInitializer
	pop = ec.Population
	pop.subpops = 1
	pop.subpop.0 = ec.Subpopulation
	pop.subpop.0.file = /this/is/the/file/with/the/Individuals.txt
	pop.subpop.0.size = 100
	pop.subpop.0.duplicate-retries = 0

3. Now when we run ECJ, it will load the individuals from our  
"Individuals.txt" file into our Subpopulation, then call evolve() on  
the TrivialEvolutionState, at which time we can do whatever we want  
with them.

Sean