1) Jaime Fernandez

Email: jjf@jjf.com

http://www.geneticprogramming.com/GPpages/software.html

2) John R. Koza

OFFICE PHONE: 650-960-8180

E-mail: koza@genetic-programming.com

http://www.genetic-programming.org/gpftpsite.html

(This webpage already includes Lee Spector’s Push Language)

R users venues that would be interested in learning about the new package

1) http://blog.revolution-computing.com/ “This is the new blog from REvolution Computing, dedicated to news and information of interest to members of the R community. We’ll focus mainly on news directly about R: announcements about new releases and packages…”

2) http://journal.r-project.org/submissions.html R-Journal articles can include an introduction to new packages

3) Send out an email to the R-mailing list: r-help@r-project.org. (must register to the list-serve first)

4) Post package on CRAN (http://www.r-project.org/)

But before the package can become the new hot thing, we just need to finalize the package…

Jeremy

PS: I have been working on formalizing what we have so far into a package that can be submitted to CRAN. Me and Dan met up yesterday and worked out some of the bugs that were happening when I tried to build the tarball. We finally were able to build it and I have filled in many of the necessary help files, description files, NAMEFILES and other necessary package files. Dan is adding and streamlining a few important things (such as adding categorical data, and more than two variables) and then we can finalize the package.

]]>

Here is how the R manual looks (although it may be totally different as Dan is working on something that may change how the whole R PushGP information transfer works):

Instructions for Users:

1) Load your data into R under these two variables:

> Xdata <- c(YOUR INDEPENDENT DATA HERE);

> Ydata <- c(YOUR DEPENDENT DATA HERE);

2) Create the file to format your data and parameters:

a) navigate to the directory which holds user files:

> setwd(“~/Desktop/AI/R/PackageFiles/UserFiles”);

b) source setParameters.R

> source(“setParameters.R”);

Configuration file will automatically be saved in the UserFiles folder as MyData.txt

c) (optional) PARAMETERS USER DEFINABLE:

here are the user options (defining them is optional):

> MyParameters <- SetParameters(Population Size, Execution Limit, Tournament Size, Mutation Rate, Crossover Percentage, Maximum Generations, Maximum Code Size, Mutation Range, Push Function Set)

here is an example of setting the parameters (the predefined parameters):

> MyParameters <- SetParameters(2000, 80, 7, 20, 70, 200, 40, .3, “FLOAT.* FLOAT.+ FLOAT.% FLOAT.DUP FLOAT.- FLOAT.SWAP FLOAT.ERC”);

Now you must export the new parameters as a configuration file:

> write(MyParameters, file = “~/Desktop/AI/R/PackageFiles/UserFiles/MyData.txt”)

Your data and parameters will be routed to PshGP (done) and your Push Function will be returned. *needs to be done* (it should be returned in the format shown in the file Function.R).

3) Now you can see the function and get Y Values for any given X Value:

> source(“RunningPushFunction.R”);

a) put in the x-value you want the y-value for, ie:

> x <- 42

b) run the function on it:

> source(“InterpretFunction.R”);

c) Display the answers (the last number in the list returned is your answer)

> Floats

##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;

}

PushLibrary.R contains all the Push Functions made in R so far. It also sets up Floats with NaN as the original value which will be deleted as soon as the interpreter is run on the first float in the function (see NewFloat.R).

In the future this function will be automatically constructed from a text file or other output from the java pushGP regression implementation, which was constructed prior by a data set inserted into R.

Run InterpretFunction.R to run the PushGP function on a chosen x value and return a vector of numbers (object(Floats)) with the y value as the final output.

RefreshStack.R: Very important! Every time any of the functions/operators/floats are called and affect the Floats vector all the positions of the stack may change as well as the values. This simply makes sure that the objects serving as place trackers in the vector are constantly updated when a function is called.

When function interpreter sees a float put it into the Floats vector.

Example of how to run this package in the R terminal:

> setwd(”~/Desktop/AI/R/PackageFiles”);

Error: syntax error

> setwd(“~/Desktop/AI/R/PackageFiles”);

> source(“PushLibrary.R”)

> objects()

[1] “a” “A” “b” “B”

[5] “C” “FLOATadd” “FLOATdivide” “FLOATdup”

[9] “FLOATmultiply” “Floats” “FLOATsubtract” “FLOATswap”

> source(“Function.R”)

> GPfunction

function(x) c(5.0, 7.0, “FLOAT.+”, “FLOAT.*”, “FLOAT.%”, “FLOAT.SWAP”, x, 6.0, “FLOAT.+”, 1.0, “FLOAT.SWAP”)

> x <- 42

> Floats

[1] NaN

> source(“InterpretFunction.R”)

Warning messages:

1: NAs introduced by coercion

2: NAs introduced by coercion

3: NAs introduced by coercion

4: NAs introduced by coercion

5: NAs introduced by coercion

6: NAs introduced by coercion

> Floats

[1] 12 1 48

<html>

<head>

<script src=”push.js”></script>

<script>

function main()

{

var x = new Array(“1.1″,”2.1″,”3.1″,”4.1”);

for (i=0;i<=3;i++)

{

// push function manually pasted from regression1.pushgp

var form = new String(“5.0 7.0 FLOAT.+ FLOAT.* FLOAT.% FLOAT.% FLOAT.* FLOAT.SWAP FLOAT.+ ” + parseFloat(x[i]) + ” FLOAT.* 6.0 FLOAT.+ 1.0 FLOAT.- FLOAT.SWAP FLOAT.-“);

var program = pushParseString(form);

var interpreter = new pushInterpreter();

var info = pushRunProgram( interpreter, program )

document.write(interpreter.floatStack.toString());

}

}

main();

</script>

</head>

<body>

</body>

</html>

Jeremy & Dan

]]>October 7, 2009

by Jeremy Koelmel (jpk07)

R Basics, Here is how to:

1) to manually set up data in R

2) Import data from outside R (as .txt)

3) export data out of R (as .txt)

4) To export and import R code to run in R

# writing simple exponential data in R

#assign arrays

X <- c(1:10);

Y <- c(X^2);

#matrix

XYdata <- cbind(X,Y);

#transpose data

XYdata <- t(XYdata);

#select one

XYdata[,7];

# Plot

plot(X, Y, main=”Exponential Function”);

#exporting

write.table(XYdata, file=”Desktop/XYdata.txt”, sep=”,”);

#getting the working directory

getwd();

#setting the working directory

setwd(”~/Desktop”);

#Importing

RoseData <- read.table(file=”RoseData.txt”);

#see all plots

plot(RoseData, main=”Multiflora Rose Distribution in a Pine Stand”);

#comparing two variables

MFRdensity <- RoseData[,3];

DistanceFromEdge <- RoseData[,9];

plot(DistanceFromEdge,MFRdensity);

#lm(DistanceFromEdge,MFRdensity); not working because more than one instance of y for single x

# Writing .R function: Write in a simple text format (.txt) and Save as “blahblah”.R

# ie. in this format

X <- c(1:10);

Y <- c(X^2);

XYdata <- cbind(X,Y);

plot(X, Y, main=”Exponential Function”);

# get to the right directory

setwd(”Dir”);

# enact it in R

source(”Graph.R”);

Love Jeremy

PS: Further Resources:

http://www.math.ilstu.edu/dhkim/Rstuff/Rtutor.html

http://www.cyclismo.org/tutorial/R/

]]>While we were working on this though all sorts of little problems came up that we needed obscure workarounds to deal with. At the core of most these issues was that all the work was being done externally from R. So I think it might be actually useful for us to go back and actually implement the core classes of Psh in R using rJava rather than obscure workarounds. This will take a little longer but it will give us more control over how everything runs and in the end should be much more useful.

]]>