Skip to main content
gamedev.net
🔒 Locked

Anything missing from this GP implementation?

Started by Dwiel Apr 18, 2004 at 7:38 PM 5 replies 750+ views
Original Post
Dwiel
Dwiel
Hello, I have a fairly full featured GP system created and was creating the docs for the lua function set which will be provided. A little about this system. THe goal is to have cretaed one of the most easily extensible GP system. It is setup where, it executes a lua script that you give to it. all of the functionallity of the system is shown to the lua script and you can choose how to use it. My goal is for this system to be VERY flexible. These are the functions that I have come up with in order to expose the system to the lua scripts. Does anyone have any ideas for changes on these? I will show you what I have and then explain some high level stuff after:
Group*		NewGroup()
RPG*		NewRPG()
Mutator*	NewMutator()
SampleGen*	NewSampleGen()
Environment*	NewEnvironment()
dispsettings*	NewDispSettings()
progsettings*	NewProgSettings()
env*		NewEnvironemnt()

///////////////////////////////////////

// RPG functions

///////////////////////////////////////


void		RPG_LoadFunctionSet( string filename )

	This function reads in a list of function names to load into the function set from the plaintext file found at filename.

void 		RPG_SetHeightLimits( int min, int max )

	This sets the limits on how large or small a random tree can be.  The tree will have no more than max depth and will be a complete tree up until the min depth.  These settings are always in effect, even with other methods of RPG.

void		RPG_CreatePrograms( RPG* rpg, Group* groupmain, int numof )

	Creates numof programs using settings in rpg, and adds them to groupmain.

///////////////////////////////////////

// Mutator functions

///////////////////////////////////////


void		Mutator_SetType( Mutator* mutator, string type )

	Sets the type of the mutator.  The standard options here are "Mutate", "Crossover", "Relocator" and "Collection".  many functions are only applicable when the mutator is of a certain type.  The types will specified under those functions.

void		Mutator_OnlyReplaceLikeNodes( Mutator* mutator, bool newval )

	ONLY APPLICABLE WHEN TYPE "MUTATE" OR "CROSSOVER"
	When true, the mutator will replace nodes with other nodes of the same type: functions with other functions, terminals with the same type of terminal.

void		Mutator_PreserveAirity( Mutator* mutator, bool newval )

	ONLY APPLICABLE WHEN TYPE "MUTATE" OR "CROSSOVER"
	This function will make sure that when a function is replaced, it is replaced by one with the same airity.  This may limit the effectiveness of the GP... be cautious when using it.

void		Mutator_AddMutator( Mutator* mutator, Mutator* newmut )

	ONLY APPLICABLE WHEN TYPE "COLLECTION"
	This will add a mutator to the collection.  This type is used so that multipule mutators can be put into one and called all at the same time.

void		Mutator_MutateSample( Mutator* mutator, Sample* smpl )

	Mutates EVERY program in the sample.  If a program is included twice, it is mutated twice.

///////////////////////////////////////

// SampleGen functions

///////////////////////////////////////


void		SampleGen_SetType( SampleGen* smplgen, "Basic_Percent" )

	Sets the SampleType.  Keep in mind that although custom sample methods can be employed, this will be slower due to the extra interface between lua and C... Not sure what the difference will be, just make sure you are aware of it.  Some built in Tpyes include:
		"Basic_Percent": might sort in some order if you tell it to, then only select the top or bottom % of programs.
		"Basic_Constant": might sort in some order if you tell it to, then only select the top or bottom x # of programs.  the # of programs chosen is independent of the # of programs in the group.

void		SampleGen_AddGroup( SampleGen* smplgen, Group* groupmain )

	Adds a group to the sample''s population.  Not sure what to do yet when you add a group and it contains programs that are already included...  Will be an option when I get around to it.

void		SampleGen_SortMethodAscending( SampleGen* smplgen, string var )

	This will sort the programs in ascending order using a variable defined for all of the programs.  Programs that don''t have that variable will be put at the... end or begenning... should probobly make that an option... dang.  The only default is score, which all programs have by default.

void		SampleGen_SortMethodDescending( SampleGen* smplgen, string var )

	See SampleGen_SortMethodAscending.

void		SampleGen_SetPercentChosen( SampleGen* smplgen, float per )

	Sets the percentage of programs selected out of the population.  a positive percent selects the top percent, and negitive the bottom.

void 		SampleGen_IncludeGroups( SampleGen* smplgen, bool newval )

	Iff true, allows groups to be in the population.

void		SampleGen_IncludeGroupsRec( SampleGen* smplgen, bool newval )

	Iff ture, sub-groups are also added to the population.

void		SampleGen_IncludePorgrams( SampleGen* smplgen, bool newval )

	Iff true, allows programs to be in the population.

void		SampleGen_IncludeProgramsRec( SampleGen* smplgen, bool newval )

	Iff ture, programs in sub-groups are also added to the population.

Sample*	SampleGen( SampleGen* smplgen )

	Creates a sample from the settings loaded into smplgen.

///////////////////////////////////////

// DispProg Functions

///////////////////////////////////////


void		DispProg_Rec( DispSettings* dispsettings, bool newval )

	When true, every sub-group is alse displayed.

void		DispProg_Group( DispSettings* dispsettings, Group* groupmain )

	Displays every program in the group.  If the recursive setting is selected, every sub-group is also displayed

///////////////////////////////////////

// Group Functions

///////////////////////////////////////


void		Group_AddADF( Group* group, Group* adf )

	This adds the group adf to the list of ADF groups in group.

void		Group_AddConstraint( Group* group, string type, int data )

	This will add a constraint of type type with the argument of data to Group .  This so far has no application other than to help the user avoid mistakes.  Similar to using a strongly typed system.  If the user knows that the group should never have children groups, then they may specify at creation time and be warned later if someone tried to break this constraint.  Created with ADFs in mind.

void		Group_SetDefaultProgramSettings( Group* group, ProgSettings* progsettings, [bool applytoadfs = true], [bool applytonormal = true], [bool applytochildren] )

	All programs which are added to this group get these settings by default.  if applyto adfs is true, the settings apply to adfs, (defaults to true).  Same goes form applytonormal.  Applying to children will only work if the children dont have default settings of their own.

void		Group_RemoveDefaultSettings( Group* group )

	Removes the default settings of the group.

///////////////////////////////////////

// Environment Functions

///////////////////////////////////////


void		Environment_SetDefault( Environment* env )

	subsoqiently created programs will have this environment by default

void		Environment_LoadTxtData( Environment* env, string filename )

	loads the file filename in txt format.  I need to specify somewhere the standards for the text file.

void		Environment_NextData( Environment* env )

	Increments the data previously loaded from file or inserted through function calls.

void		Environment_PrevData( Environment* env )

	See Environment_NextData.

void		Environment_AddVariable( Environment* env, string varname )

	Adds a variable to the environment.

void		Environment_AddVariablesFromFile( Environment* env, string filename )

	Opens the file in filename and adds the list of variables seperated by a comma or newline to the environment.

void		Environment_RemoveVariable( Environment* env, string var )

	Removes the variable var from the list of varaibles.

///////////////////////////////////////

// Program Settings Functions

///////////////////////////////////////


void		ProgSettings_AddVariable( ProgSettings* progsettings, string varname, string fnname )

	Adds a variable to the program settings.

void		ProgSettings_RemoveVariable( ProgSettings* progsettings, string varname, string fnname )

	Removes a variable to the program settings.

void		ProgSettings_SetDefault( ProgSettings* progsettings )

	All new programs will default to these settings.  Keep in mind that the default settings for groups take priority over this defualt.

void		ProgSettings_ApplyToSample( ProgSettings* progsettings, Sample* smpl )

	Applies the settings to all of the programs in the sample...  should this have priority over the default settings of the group?
I also have an RTF vertion but my server doesn''t seem to want to accept it... A simpel lua script is as follows:
	-- create all of the objects we will need
groupmain = NewGroup()
rpgmain = NewRPG()
mutator = NewMutator()
smplgen = NewSampleGen()
envirn  = NewEnvironment()
	-- progdisp = NewProgramDisplay()
	-- there is only 1 static program displayer...
	--	just use the functions

RPG_LoadFunctionSet( "Default.fns" )

	--           min, max
RPG_SetHeightLimits( 3,   5 )

	--          rpg,     group,     numofprogs 
RPG_CreatePrograms( rpgmain, groupmain, 100 )

	-- Mutator_SetType( mutator, "Crossover" )
	-- Mutator_SetType( mutator, "Relocator" )
Mutator_SetType( mutator, "Mutate" )

	-- this is specific to this type of mutator.
	--	if this were attempted on a mutator which
	--	doesn''t support it, a pretty error in the
	--	C++ code should tell us about the mistake.
Mutator_OnlyReplaceLikeNodes( true )

	-- similar to the mutator''s Set Type
SampleGen_SetType( smplgen, "Basic" )

	-- this function tells smplgen to generate its 
	--	samples from this group.
SampleGen_AddGroup( smplgen, groupmain )

	-- this also is specific to this type. (see above)
SampleGen_SetPercentChosen( smplgen, 0.05 )

for i = 0, 100 do
	smpl = SampleGen( smplgen )
	Mutator_MutateSample( mutator, smpl )
end

	-- this function is not recursive by default
	--	this group has no children groups so this
	--	isn''t an issue.  Use DispProg_GroupRec()
	--	when it is.
DispProg_Group( groupmain )
That script would run 100 generations on a simgle population of 100 programs... not to useful, but you get the idea. I would like to know if anyone has any suggestions as to what functionality would be nice. Or if there is any part which isn''t straight forawrd, I''d be happy to explain some more so it is. My hope is that is pretty straight-forward to anyone familiar with GP. lets here the comments! Thanks in advance! Dwiel
My home page!!!
Find out about my diy LCD projector and programming projects!
Dwiel
Dwiel
Well, either my design is perfect , or people dont really care about GP.

Out of curiosity, now many others of you have implememnted a GP system? How did you do it? i''d love to hear how you set things up.

Dwiel

P.S. I''ve also got some update to the list if anyone is interested... I''ll probobly post later when I have it complete... maybe it will bring more interest then.

My home page!!!
Find out about my diy LCD projector and programming projects!
Timkin
Timkin
quote:
Original post by Tazzel3D
Well, either my design is perfect , or people dont really care about GP.



I think the problem is that very few people really have the time or inclination to read through someone elses code, decipher what it does and then comment on its suitability for the task. Personally, I understand GP very well, but I don''t know the Lua language, so I''m not really inclined to try and decipher it. I''m sure there are others like me around here.

Don''t be discouraged if you don''t get any useful answers. In that case, you might ask for the thread to be moved to the Game Programming forum, where you might receive more assistance from Lua programmers.

Cheers,

Timkin
Dwiel
Dwiel
Thanks for the reply

I guess I need to change it a bit so that other people can help me easier...

I guess I should have mentioned that the fact that I am using lua is really irrelivent. My goal is to make an interface for my GP system based on function calls to various systems. The code I posted at the top was the list of my functions so far. They are in order by what class/namespace they would be in if you wanted to use a style like that. What I will do is describe a little of each of my proposed 'system's to see if you guys think it is a complete set of tools to access /creat/work with/execute GPs. Most of all, does the design seem to handle what YOU might want to test out? I want this to be flexible.

So for the basic description of this system:

There are some basic types which you can use to create your system. They include:

Group
SampleGen(erator)
Mutator
RPG (RandomProgramGenerator)
Environment

A group is what is used to create the structure of your population of programs. A group contains a list of children programs. It also may have a pointer to groups which contain ADFs (Koza 1992).

An Environment is just as it sounds, an environment which programs execute. They hold all of the data that is to be acessable to the GP along with any 'local' variables or functions. Every program contains a pointer to one of these.

An RPG simply generates random programs and/or expr trees. It is used to create random programs to initialize the population and also later if new ones are to be inserted (you reach a local max) or entire random trees are to be inserted into an already existing program.

[EDIT] forgot this one.. doh
A Mutator can mutate any given programs in a # of ways. One way is for it to do a mutation. It can also perform crossovers and relocate. A relocating mutator, simply moves programs from one group to another. You can instruct it to not change the airity of functions when mutating/crossing or simply limit it to replace like types. Example fns with other fns and terminals with other terminals.

Last but not least, you have a SampleGenerator. This thing does a lot. All you do is give it a population of programs, tell it how you want it to sort these programs, and then what percent of them you want. You could also ask for the top 10... This is very simple, but carries a lot of functionality. Say you want to save the programs that did well and mutate the rest. You'd give this a population of every program, sort them by their score, and then select the worst 95%. pass this sample to the mutator and you have done what you wanted. kept the top 5% and mutated the rest. Also keep in mind that you can define your own variables attributed to each program so can sort them in many ways.

Hopefully, this is language independant and makes more sence.

Does this system seem like a logical way of setting things up? Are there any setups that you might want to try with it that dont sound possible? waht are they?

Thanks a bunch

Dwiel

My home page!!!
Find out about my diy LCD projector and programming projects!


[edited by - Tazzel3d on April 19, 2004 10:07:26 PM]
SDickson
SDickson
If a person doesn''t get to the point within a couple of paragraphs, I stop reading.

Be succint and ask specific questions.
IADaveMark
IADaveMark
quote:
Original post by SDickson
If a person doesn''t get to the point within a couple of paragraphs, I stop reading.
Then is it such a loss to have eliminated the help of someone who is lacking the required attention span? Seriously, welcome to the AI board where page-long posts are the norm.



Dave Mark - President and Lead Designer
Intrinsic Algorithm -
"Reducing the world to mathematical equations!"
Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit<
Dwiel
Dwiel
quote:
Original post by InnocuousFox
quote:
Original post by SDickson
If a person doesn''t get to the point within a couple of paragraphs, I stop reading.
Then is it such a loss to have eliminated the help of someone who is lacking the required attention span? Seriously, welcome to the AI board where page-long posts are the norm.


I was about to implement a GP system and I wanted to see if anyone had any suggestions as to how I could improve my design... its no big deal, I''ll just try it out and see how it all works out.

I normally dont post so long, but I needed to explain an entire GP system... I did my best to be succint.

I am truly sorry I put my time into explaining my entire GP system to you (SDickson). Next time maybe I should just avoid trying for advice here and save my time.

I''ll let you guys know how well it works when I finsih, and release it to the public so other can benefit from it. I also have many experiments as to how simplifying programs effects effeciency (in evolution), if grouped populations with the program''s ability to migrate to other ''ecosystems'' helps, etc.

Eventually, I am going to use it to see how well a system can do in the stock market.

Dwiel



My home page!!!
Find out about my diy LCD projector and programming projects!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.