[R] Advice for speeding up optim()

Pinto, Naiara (334F) n@|@r@@p|nto @end|ng |rom jp|@n@@@@gov
Wed Apr 3 04:13:34 CEST 2019

Hi all,

I’m calling optim() and getting correct results, but need help to upscale it. I need to call it on a matrix that’s 3000x5000. I know the SANN option is slow but I get similar results with all other options. Perhaps there’s another package..I also heard about implementing my loss function in the cpp core but I’m not sure what this entails. I do have bounds for both parameters. My function is below – thank you in advance for your patience and suggestions!

rvog = function(x){
                ext = x[1]
                height = x[2]
                ext_linear = ext * log(10)/20 #change units to nepers per meter
                inc_radians = myinc *pi/180
                p1 = 2*ext/cos(inc_radians)
              p2 = p1 + 1i*mykz
                #minimize distance to a provided coherence value
              coh = abs(mycoh - ((p1 / p2) * ((exp(p2*height)-1) / (exp(p1*height)-1))))
                return (coh)

#ancillary variables
mykz = kz[i,j]
myinc = inc
mycoh = volume

#call optimization function
myoptim = optim(c(0.05,30), rvog, method = "SANN", control = list(maxit = 30000, temp = 2000, trace = FALSE))


	[[alternative HTML version deleted]]

More information about the R-help mailing list