Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to perform any symbolic regression with rgp

Tags:

r

I have this simple code:

library(rgp)
df1 <- data.frame(x=1:10, y=sin(1:10))
grp.model <- symbolicRegression(y ~ x, df1, functionSet=functionSet("sin"))

When I execute I get the error

STARTING genetic programming evolution run (Age/Fitness/Complexity Pareto GP search-heuristic) ...
Error in mse(x, y) : Argument 's_y' is not a real vector.

I have tried the examples from https://cran.r-project.org/web/packages/rgp/vignettes/rgp_introduction.pdf, but all the examples give me nonsense constant functions.

What am I doing wrong ?

I am using R version 3.1.2 with rgp_0.4-1.

Cheers.

like image 201
Antoine Trouve Avatar asked Aug 18 '16 03:08

Antoine Trouve


1 Answers

I too get the same error. The documentation for the erroring-out function mse states that it require "a numeric vector or list" for its arguments.

Running the str command to look at the data frame's structure indicates that x is an integer type.

> str(df1)
'data.frame':   10 obs. of  2 variables:
 $ x: int  1 2 3 4 5 6 7 8 9 10
 $ y: num  0.841 0.909 0.141 -0.757 -0.959 ...

Try using as.numeric() on the x vector:

library(rgp)
df1 <- data.frame(x=as.numeric(1:10), y=sin(1:10))
grp.model <- symbolicRegression(y ~ x, df1, functionSet=functionSet("sin"))
like image 92
weskimmo Avatar answered Oct 20 '22 06:10

weskimmo