setting PshGP user definable parameters in R

October 23, 2009
by Jeremy Koelmel (jpk07)

In order to set user definable parameters in R that can be read in Java I have made the exact text that the java PshGP uses to configure the linear regression GP in R. This text is separated in a function with all the aspects of the text that are user definable (such as data input) as variables in the function. Hence users will only have to do SetParameters(…) and fill in any specifics they want to change, or let it run at default.

##Data Formatting (They would set Xdata and Ydata as their own data)
Xdata <- c(1,2,3,4);
Ydata <- c(2,4,6,8);
XYdata <- cbind(Xdata,Ydata);
DataFormatted <- cbind(Xdata,Ydata);
for (i in 1:length(Ydata))
{
FirstParenth <- c(“( “);
LastParenth <- c(” )”);
DataFormatted[i,1] <- paste(FirstParenth, DataFormatted[i,1]);
DataFormatted[i,2] <- paste(DataFormatted[i,2], LastParenth);
DataForm <- paste(DataFormatted[1:i,1], DataFormatted[1:i,2]);
};
Data <- (“(“);
for (i in 1:length(DataForm))
{
Data1 <- DataForm[i];
Data <- paste(Data,Data1);
};

## making user definable
SetParameters <- function(Pop=2000, Exec=80, Tourn=7, Mut=20, Cross=70, Gen=200, Code=40, Fair=.3,
DataIn=Data, FunctionSet=”FLOAT.* FLOAT.+ FLOAT.% FLOAT.DUP FLOAT.- FLOAT.SWAP FLOAT.ERC”) {
## Random Comments, formatting and Text preservation
TextIntro <- c(“\n#\n# A sample PushGP file for a simple test symbolic regression problem.# In this demo, the system solves the equation y = 12x^2 + 5.\n#\n# Jon Klein <jk [at] spiderland.org>\n# 06/14/2008\n#\n\n### We can optionally read in some additional parameters\ninclude standard.pushgp\n\n### Setup some standard GP parameters\n\npopulation-size =”);
TextIntro2 <- c(“\n\n### The problem class determines how test cases are setup and\n### how fitness scores are computed.  The FloatSymbolicRegression\n### class uses a set of float inputs and a single output.\n\nproblem-class\t\t=org.spiderland.Psh.FloatSymbolicRegression\n\ntest-cases\t\t= “);
TextIntro3 <- c(“)\n\n### Other possible ways of defining test cases\n\n# test-case-class \t= Problem1Generator\t# at runtime from code\n# test-case-xml\t\t= Problem1.xml\t\t# from an XML file\n# test-case-csv\t\t= Problem1.csv\t\t# from a comma separated value file\n\ninstruction-set = ( “);
TextIntro4 <- c(“))”);
TextExecLimit <- c(“\nexecution-limit         = “);
TextTournSize <- c(“\ntournament-size         = “);
TextMutPerc <- c(“\nmutation-percent        = “);
TextCrossOver <- c(“crossover-percent       = “);
TextGenerations <- c(“\nmax-generations         = “);
TextCodeSize <- c(“\nmax-random-code-size    = “);
TextFairMut <- c(“fair-mutation-range     =”);
## Evolution Parameters user determined (or not)
Population <- Pop;
ExecLimit <- Exec;
TournSize <- Tourn;
MutPerc <- Mut;
CrossOver <- Cross;
Generations <- Gen;
CodeSize <- Code;
FairMut    <- Fair;
FunctSet <- FunctionSet;
##Setting up whole regression text file
Regression1 <- paste(TextIntro, Population, TextExecLimit, ExecLimit, TextTournSize, TournSize, TextMutPerc,
MutPerc, TextCrossOver, CrossOver, TextGenerations, Generations, TextCodeSize, CodeSize, TextFairMut, FairMut,
TextIntro2, Data[1:length(Data)], TextIntro3, FunctSet, TextIntro4);
Regression1;
}



Leave a Reply

You must be logged in to post a comment.