[Rd] New code -- genetic algorithm curve fitting (supports complex numbers)
Tue, 8 Aug 2000 15:11:19 +1000
OK, here is some code that may be of use to someone:
Hopefully it might make contrib status on CRAN :-)
It uses a genetic algorithm to seek the lowest value of some
user-defined target function (or seeks the most negative value if negative
values are possible). By using a sum of squared residuals for the target
function, it supports least square nonlinear regression.
Any comments welcome, the algorithm is completely thrown together
out of my head (in about three days) but I have written genetic
algorithms before, the same ideas can be found elsewhere.
If you have an optimisation problem, you should be able to apply
my code to it within half an hour or so because it doesn't require
much knowledge to use. I would be interested if anyone can find a
problem that crashes it. I'm sure that there are many problems for
which it will get something roughly reasonable but not quite right --
this is in the nature of a stocastic search <shrug>. The user has
some control over ``thermal'' noise so setting that to a small value
can help squeeze a bit more accuracy out of it.
I did finally bludgeon nls into complex number support,
I intend to release the patches to make this work but it is not
particularly elegant -- it just converts EVERYTHING that goes
through the target function into a vector of reals. Thus it does
handle wide data and complex numbers but it treats them all by
just breaking them down into individual reals and squaring the
Sadly, when I finally did get it working it still didn't do what
I wanted because my function kept stopping with stepsize being
reduced below the minimum. On close analysis, I decided that the
nls function will stall in a local minimum if it follows the
gradient into such a minimum and then just keeps reducing its
step size until it halts with an error. This does seem to imply that
a large number of model functions will not work with nls
until a suitably close starting value can be found.
My genetic algorithm code may provide one method to find such
values that are somewhere close to a good fit.
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: email@example.com