Creating functions with memory?

56 views
Skip to first unread message

Thomas Macrina

unread,
Jun 23, 2014, 12:45:59 PM6/23/14
to deap-...@googlegroups.com
Hey brothers,

I'd like to incorporate functions within my strongly-typed GP individuals that remember their previous state. Here's a simple example of where I stand now. The commented function on line 26 is a rough idea of where I'd like to head.

Does anybody have any thoughts on a good way to go about this?

A couple initial brainstorms:
  • I could pass a flexible list as an input to my compiled individual that would contain the previous states of my functions with memory.
  • I could use the individual to first initialize a series of classes (in a fashion similar to the __str__ method of the PrimitiveTree), then pass that series of classes as an input to the compiled individual along with the varied inputs.
  • I could somehow extend the Primitives class to have an optional previous state attribute.
Thanks for the help, guys.

Tommy

Milon

unread,
Jun 25, 2014, 3:42:19 AM6/25/14
to deap-...@googlegroups.com
Hi,

I don't know what you mean by "previous_sum" in your example. Anyway I guess "named memory" (or registers) might solve your problem - supply the program with a dictionary/list and in functions access it by name/index.

Or see Genetic Programming III from Koza, page 155: Automatically Defined Storage

Milon

Félix-Antoine Fortin

unread,
Jun 26, 2014, 10:25:24 AM6/26/14
to deap
Hi Thomas,

I have not taken much time to think about it, but I have to make a warning before hands. The function that is added to the primitive set is shared by every individual. Therefore, if it has some form of memory, every individual execution will affect its memory, and I doubt this is what you want.

If your function needs to remember a state, you should probably make the function a method of a new class and save the state in that class. You can then register in the pset the object's method. Just remember to reset the object state before each execution of a tree. If you want an example, take a look at the Artificial Ant example:

Regards,
Félix-Antoine


--
You received this message because you are subscribed to the Google Groups "deap-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to deap-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Thomas Macrina

unread,
Jun 26, 2014, 4:00:57 PM6/26/14
to deap-...@googlegroups.com
Thanks, Milon & Felix. I wound up working more in the global class direction. Here's what I put together. Hopefully that scales okay.

For anyone interested, most of the pages on the Automatically Defined Storage chapter of Koza's book that Milon mentioned are here.

Thanks again, guys!

Tommy
Reply all
Reply to author
Forward
0 new messages