Eva - 6 months ago 44

R Question

I'm checking a simple moving average crossing strategy in R. Instead of running a huge simulation over the 2 dimenional parameter space (length of short term moving average, length of long term moving average), I'd like to implement the Particle Swarm Optimization algorithm to find the optimal parameter values. I've been browsing through the web and was reading that this algorithm was very effective. Moreover, the way the algorithm works fascinates me...

Does anybody of you guys have experience with implementing this algorithm in R? Are there useful packages that can be used?

Thanks a lot for your comments.

Martin

Answer

Well, there is a package available on CRAN called pso, and indeed it is a particle swarm optimizer (PSO).

I recommend this package.

It is under actively development (last update 22 Sep 2010) and is consistent with the reference implementation for PSO. In addition, the package includes functions for diagnostics and plotting results.

It certainly appears to be a sophisticated package yet the main function interface (the function **psoptim**) is straightforward--just pass in a few parameters that describe your problem domain, and a cost function.

More precisely, the key arguments to pass in when you call *psoptim*:

dimensions of the problem, as a vector (

*par*);lower and upper bounds for each variable (

*lower, upper*); anda cost function (

*fn*)

There are other parameters in the *psoptim* method signature; those are generally related to convergence criteria and the like).

Are there any other PSO implementations in R?

There is an R Package called ppso for (parallel PSO). It is available on R-Forge. I do not know anything about this package; i have downloaded it and skimmed the documentation, but that's it.

Beyond those two, none that i am aware of. About three months ago, I looked for R implementations of the more popular meta-heuristics. This is the only pso implementation i am aware of. The R bindings to the Gnu Scientific Library GSL) has a simulated annealing algorithm, but none of the biologically inspired meta-heuristics.

The other place to look is of course the CRAN Task View for Optimization. I did not find another PSO implementation other than what i've recited here, though there are quite a few packages listed there and most of them i did not check other than looking at the name and one-sentence summary.