[R] problems with rgp, examples from documentation won't produce expected results
Bernd
prof7bit at gmail.com
Tue Jul 21 21:28:33 CEST 2015
I am currently playing with the rgp package, trying to find out how
the symbolic regression works but I am having trouble getting any
reasonable results.
I have found this pdf:
https://cran.r-project.org/web/packages/rgp/vignettes/rgp_introduction.pdf
and am currently trying to follow the pendulum example in chapter 4.3
(after I failed to make *any* of my own experiments produce any
results at all).
>From the PDF in chapter 4.3 I have copy-pasted the relevant code
snippets into one file, now I have the following:
# -----8<-----8<-----8<---- cut here
library("rgp")
set.seed(1)
makeDampedPendulum <- function(A0 = 1, g = 9.81, l = 0.1, phi = pi,
gamma = 0.5) {
omega <- sqrt(g/l)
function(t) A0 * exp(-gamma * t) * cos(omega * t + phi)
}
pendulum1 <- makeDampedPendulum(l = 0.5)
xs1 <- seq(from = 1, to = 10, length.out = 512)
pendulum1Data <- data.frame(time = xs1,
deflection = pendulum1(xs1) + rnorm(length(xs1), sd = 0.01))
modelSet1 <- symbolicRegression(deflection ~ time, data = pendulum1Data,
stopCondition = makeStepsStopCondition(8000))
bestModel1 <- modelSet1$population[[which.min(modelSet1$fitnessValues)]]
plot(y = bestModel1(xs1), x = xs1, type = "l", lty = 1, xlab = "x", ylab = "y")
lines(y = pendulum1(xs1), x = xs1, lty = 2)
# -----8<-----8<-----8<---- cut here
In the PDF it says it would produce a function (even after only 2
minutes), that fits to the data like the one depicted in fig. 1 on
page 3 but all I get is:
> bestModel1
function (time)
-2.97507503535599/(exp(time)/(0.280210268683732/time))
Sometimes it even produces just a constant term and no dependency on
time at all! What am I missing here, what needs to be done to make it
try more complicated expressions, to make the example in the PDF work
as described?
TIA,
Bernd
More information about the R-help
mailing list