Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parallel optimization in R

This question came at the right time, as I'm struggling with optimization as well. I am aware of the different "normal" optimization routines in R, and I am aware of parallel packages like snow, snowfall, Rmpi and the likes. Yet, I didn't manage to get an optimization running in parallel on my computer.

Some toy code to illustrate :

f <- function(x) sum((x-1:length(x))^2)
a <- 1:5
optim(a,f)
nlm(f,a)

What I want to do, is to parallelize the optim() function ( or the nlm() function, which does basically the same). My real function f() is a lot more complicated, and one optimization round lasts about half an hour. If I want to run a simulation of 100 samples, that one takes ages. I'd like to avoid writing my own Newton-like algorithm for parallel computing, so I hope somebody could give me some hints on how to use parallel computing for complex optimization problems in R.


I reckon this problem is of a different nature than the one in the related question. My request is specifically directed towards parallel computing, not some faster alternative for optim.

like image 450
Joris Meys Avatar asked Sep 21 '10 11:09

Joris Meys


2 Answers

To answer my own question :

There is a package in development that looks promising. It has Particle Swarm Optimization methods and builds on the Rmpi package for parallel computing. It can be found on Rforge :

http://www.rforge.net/ppso/index.html

It's still in beta AFAIK, but it looks promising. I'm going to take a look at it later on, I'll report back when I know more. Still, I leave the question open, so if anybody else has another option...

like image 93
Joris Meys Avatar answered Nov 18 '22 00:11

Joris Meys


The R package optimParallel could be helpful in your case. The package provides parallel versions of the gradient-based optimization methods of optim(). The main function of the package is optimParallel(), which has the same usage and output as optim(). Using optimParallel() can significantly reduce optimization times as illustrated in the following figure (p is the number of paramters). enter image description here See https://cran.r-project.org/package=optimParallel and http://arxiv.org/abs/1804.11058 for more information.

like image 42
Nairolf Avatar answered Nov 18 '22 00:11

Nairolf