Re: [R] A faster way to compute finite-difference gradient of ascalarfunction of a large number of variables

2008-03-27 Thread Dimitris Rizopoulos
If 'myfunc' is a vector function and can be vectorized in R, then it is even faster to use the following: grad.vec - function(x, fn, ..., eps = sqrt(.Machine$double.neg.eps)){ x1 - x + eps * pmax(abs(x), 1) x2 - x - eps * pmax(abs(x), 1) (fn(x1, ...) - fn(x2, ...)) / (x1 - x2) }

Re: [R] A faster way to compute finite-difference gradient of ascalarfunction of a large number of variables

2008-03-27 Thread Ravi Varadhan
Thank you, Dimitris Christos. Yes, myfunc is a scalar function that needs to be minimized over a high-dimensional parameter space. I was afraid that there might be no better way, apart from coding in C. Thanks, Dimitris, for confirming my fear! Best regards, Ravi.

Re: [R] A faster way to compute finite-difference gradient of ascalarfunction of a large number of variables

2008-03-27 Thread Prof Brian Ripley
On Thu, 27 Mar 2008, Ravi Varadhan wrote: Thank you, Dimitris Christos. Yes, myfunc is a scalar function that needs to be minimized over a high-dimensional parameter space. I was afraid that there might be no better way, apart from coding in C. Thanks, Dimitris, for confirming my fear!