Print

Print


Sean,

Thanks very much, I was referring to GP. Does this mean that individuals
form one generation are never carried straight over to another (i.e. they
are always cloned)?

For my application, in clone(), I think i need to do 
bar = new ArrayList();
since i want the array list to be empty at the start of every generation
(you were correct, I do not want them pointing to the same place). So, foo2
and foo3 both are in the new population and foo2.bar and foo3.bar are both
empty.

Can foo ever be in the new population as well (say, if the individual it is
a part of is carried over unaltered)? If foo can be in the new population,
is there a way to ensure that foo.bar is reinitialized? Or, are individuals
always cloned somehow before being placed in the new population? 

Thanks,

Jake

On Fri, 22 Jan 2010 18:29:42 -0500, Sean Luke <[log in to unmask]> wrote:

>Jake, I presume you're talking about GP.  GPNodes, GPTrees, and
>GPIndividuals all basically work like this: after a population is
>evaluated, typically the individuals undergo breeding to create new
>individuals, and then are usually eliminated.  Breeding works by
>cloning subtrees, and ultimately nodes, from the old individuals to
>form new individuals.  The clone method used is lightClone(), which
>ultimately calls clone() underneath.
>
>So let's say you've made got a GPNode called 'foo' which has an
>ArrayList called foo.bar.  'foo' is located in some GPIndividual, and
>the GP system has decided to copy that individual, and the subtree
>where 'foo' is located, to create a new child for the next
>generation.  We call foo.clone().  This creates a new object (call it
>foo2).  foo2.bar is pointing to the same ArrayList as foo.bar now.
>Now we create another new child from foo (foo's lucky!) called foo3.
>foo3.bar and foo2.bar BOTH are pointing to the same ArrayList as
>foo.bar is.
>
>This may be what you want, but I'm guessing it's not.  Because now you
>evaluate the new child individual that holds foo2.  It adds something
>to the foo2.bar ArrayList.  When you get around to evaluating the
>individual that has foo3, it ALSO will have that thing added into its
>ArrayList because it's the same ArrayList.  You probably were hoping
>them to have separate ArrayLists is my guess.
>
>To do that, you override the GPNode clone method for your particular
>GPNode subclass to call super.clone(), and then say something like:
>
> bar = (ArrayList)(bar.clone());
>
>Now foo2 and foo3 have their own copies of the ArrayList, different
>from the original one in foo, each storing what foo.bar had inside it,
>but able to add their own independent stuff without stepping on each
>others' toes.
>
>Sean
>
>On Jan 22, 2010, at 5:13 PM, Jake Pacheco wrote:
>
>> Specifically, I have a node that is meant to calculate the zero lag
>> exponential moving average of its child's value. This requires the
>> node
>> having access to its own value on the previous evaluation, as well
>> as the
>> child's value for several evaluations back. The way I implemented
>> this, the
>> node stores its value in a variable after calculation, and adds the
>> child's
>> value to an ArrayList. However, I am not sure if these are preserved
>> through
>> to the next evaluation, or, if they are preserved through evaluations,
>> whether they will be empty once the next generation starts.