FAQ
Hello everybody!

Spse I have the following

X <- seq(1:100) #(a dim(100) sequence of integers 1:100 representing
the possible actions of player 1 and player2 in a game)
BR2X<- br2(X) #(a dim(100) sequence of points on range (1,100)
representing the best response function of player 2 to player 1:s
actions)
BR1X<- br1(X) #(a dim(100) sequence of points on range (1,100)
representing the best response function of player 1 to player 2:s
actions)

To illustrate Nash equilibrium , I would like to plot these in the same
picture, with inverted axes, so that

(X,BR2) is plotted with X on horizontal and BR2 on vertical axis
(X, BR1) is plotted with X on vertical axis and BR1 on horizontal axis.

How can I do that ?

Juhana Vartiainen
juhana.vartiainen at labour.fi

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

## Search Discussions

•  at Mar 20, 2002 at 10:34 am ⇧
HI,
On Wed, 20 Mar 2002, Juhana Vartiainen wrote:

Hello everybody!

Spse I have the following

X <- seq(1:100) #(a dim(100) sequence of integers 1:100 representing
the possible actions of player 1 and player2 in a game)
BR2X<- br2(X) #(a dim(100) sequence of points on range (1,100)
representing the best response function of player 2 to player 1:s
actions)
BR1X<- br1(X) #(a dim(100) sequence of points on range (1,100)
representing the best response function of player 1 to player 2:s
actions)

To illustrate Nash equilibrium , I would like to plot these in the same
picture, with inverted axes, so that

(X,BR2) is plotted with X on horizontal and BR2 on vertical axis
(X, BR1) is plotted with X on vertical axis and BR1 on horizontal axis.

How can I do that ?
You should do something like this:

plot(X, BR2)
lines(BR1, X) # or points(BR1, X)

Note that plot() removes everything that were in the plot window before and
calculates new axes etc., but lines() keeps the previous graph and uses the
same axes. You may consider using plot(..., lwd=2) to get the BR-lines
thicker than the axes.

Note also that you may use

X <- 1:100

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
•  at Mar 20, 2002 at 10:51 am ⇧

On Wed, Mar 20, 2002 at 09:41:04AM +0200, Juhana Vartiainen wrote:
(X,BR2) is plotted with X on horizontal and BR2 on vertical axis
(X, BR1) is plotted with X on vertical axis and BR1 on horizontal axis.
help(plot)
help(points)

as in

plot(X,BR2)
points(BR1,X)

help(par), with attention to "pch" would also probably help.

This, and more, is all in "An Introduction to R" - \$RHOME/doc/R-intro.pdf

Cheers

Jason
--
Indigo Industrial Controls Ltd.
64-21-343-545
jasont at indigoindustrial.co.nz
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
•  at Mar 20, 2002 at 12:08 pm ⇧

Jason Turner wrote:
On Wed, Mar 20, 2002 at 09:41:04AM +0200, Juhana Vartiainen wrote:
(X,BR2) is plotted with X on horizontal and BR2 on vertical axis
(X, BR1) is plotted with X on vertical axis and BR1 on horizontal axis.
help(plot)
help(points)

as in

plot(X,BR2)
points(BR1,X)

help(par), with attention to "pch" would also probably help.

This, and more, is all in "An Introduction to R" - \$RHOME/doc/R-intro.pdf
You can also generate axis for the second set of data with axis()
manually (e.g. at the top and right hand side of the plot), see ?axis
for details.

Uwe Ligges
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
•  at Mar 20, 2002 at 12:12 pm ⇧
Hello Juhana

make the first ploot as normal: plot(X, BR2)
and the second one with points: points(BR1, X, col='red')
perhaps you have to set xlim and ylim in plot, so that every point in
BR1 is shown

another aproach is:
plot(c(BR2,X),c(X,BR1),col=rep('black',length(X),),rep('red',length(X))

I hope it help

gruess

joerg

Juhana Vartiainen wrote:
Hello everybody!

Spse I have the following

X <- seq(1:100) #(a dim(100) sequence of integers 1:100 representing
the possible actions of player 1 and player2 in a game)
BR2X<- br2(X) #(a dim(100) sequence of points on range (1,100)
representing the best response function of player 2 to player 1:s
actions)
BR1X<- br1(X) #(a dim(100) sequence of points on range (1,100)
representing the best response function of player 1 to player 2:s
actions)

To illustrate Nash equilibrium , I would like to plot these in the same
picture, with inverted axes, so that

(X,BR2) is plotted with X on horizontal and BR2 on vertical axis
(X, BR1) is plotted with X on vertical axis and BR1 on horizontal axis.

How can I do that ?

Juhana Vartiainen
juhana.vartiainen at labour.fi

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
--
Joerg Maeder .:|:||:..:.||.:: maeder at atmos.umnw.ethz.ch
Tel: +41 1 633 36 25 .:|:||:..:.||.::
http://www.iac.ethz.ch/staff/maeder
PhD student at INSTITUTE FOR ATMOSPHERIC AND CLIMATE SCIENCE (IACETH)
ETH Z?RICH Switzerland
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
•  at Mar 20, 2002 at 1:31 pm ⇧
I want to maximise a function using 'optim' with a method that requires
the gradient, so I supply two functions, 'fun' for the function value
and 'd.fun' for its gradient. My question is: Since some calculations are
common to the two functions, is it possible to save time by feeding
'd.fun' with some of the calculations made in 'fun'? That would require
(at least) that it is guaranteed that each time 'd.fun' is evaluated, it
is done immediately after a call to 'fun' at the same parameter value.
The help page says:

"It is guaranteed that `gr' will be called immediately after a
call to `fn' at the same parameter values."

which is not exactly the same. However, look at this trivial example:

prov <- function(x.start = 0){
fun <- function(x) {
e.x <- exp(-x)
x * e.x
}
d.fun <- function(x) {
e.x <- exp(-x)
e.x * (1 - x)
}
optim(x.start, fun, d.fun, method = "BFGS",
control = list(fnscale = -1))
}
prov(2)\$counts
19 9

This contradicts the help page info, since that implies that the gradient
is called at least as many times as the function.

Q1: What is the correct guarantee? Is it what I need?

Q2: If so, How do I share calculations between the two functions? In my
trivial example, exp(-x) is calculated in both.

Thanks for any enlightenment! (Brian?)

G?ran
--
G?ran Brostr?m tel: +46 90 786 5223
professor fax: +46 90 786 6614
Department of Statistics http://www.stat.umu.se/egna/gb/
Ume? University
SE-90187 Ume?, Sweden e-mail: gb at stat.umu.se

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
•  at Mar 20, 2002 at 2:01 pm ⇧

On Wed, 20 Mar 2002, [iso-8859-1] Göran Broström wrote:

I want to maximise a function using 'optim' with a method that requires
the gradient, so I supply two functions, 'fun' for the function value
and 'd.fun' for its gradient. My question is: Since some calculations are
common to the two functions, is it possible to save time by feeding
'd.fun' with some of the calculations made in 'fun'? That would require
(at least) that it is guaranteed that each time 'd.fun' is evaluated, it
is done immediately after a call to 'fun' at the same parameter value.
The help page says:

"It is guaranteed that `gr' will be called immediately after a
call to `fn' at the same parameter values."
Only if hessianúLSE, and that phrase is now removed.
which is not exactly the same. However, look at this trivial example:

prov <- function(x.start = 0){
fun <- function(x) {
e.x <- exp(-x)
x * e.x
}
d.fun <- function(x) {
e.x <- exp(-x)
e.x * (1 - x)
}
optim(x.start, fun, d.fun, method = "BFGS",
control = list(fnscale = -1))
}
prov(2)\$counts
19 9

This contradicts the help page info, since that implies that the gradient
is called at least as many times as the function.
No, the other way around. It meant `if gr is called, it will be called
...'

Q1: What is the correct guarantee? Is it what I need?

Q2: If so, How do I share calculations between the two functions? In my
trivial example, exp(-x) is calculated in both.
You need to cache the par values and the results you need, and test both.
It is unlikely to be worth it.
Thanks for any enlightenment! (Brian?)

Göran
--
Göran Broström tel: +46 90 786 5223
professor fax: +46 90 786 6614
Department of Statistics http://www.stat.umu.se/egna/gb/
Umeå University
SE-90187 Umeå, Sweden e-mail: gb at stat.umu.se

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
•  at Mar 20, 2002 at 2:57 pm ⇧

On Wed, 20 Mar 2002 ripley at stats.ox.ac.uk wrote:
On Wed, 20 Mar 2002, [iso-8859-1] G?ran Brostr?m wrote:

I want to maximise a function using 'optim' with a method that requires
the gradient, so I supply two functions, 'fun' for the function value
and 'd.fun' for its gradient. My question is: Since some calculations are
common to the two functions, is it possible to save time by feeding
'd.fun' with some of the calculations made in 'fun'? That would require
(at least) that it is guaranteed that each time 'd.fun' is evaluated, it
is done immediately after a call to 'fun' at the same parameter value.
The help page says:

"It is guaranteed that `gr' will be called immediately after a
call to `fn' at the same parameter values."
Only if hessianúLSE, and that phrase is now removed.
which is not exactly the same. However, look at this trivial example:

prov <- function(x.start = 0){
fun <- function(x) {
e.x <- exp(-x)
x * e.x
}
d.fun <- function(x) {
e.x <- exp(-x)
e.x * (1 - x)
}
optim(x.start, fun, d.fun, method = "BFGS",
control = list(fnscale = -1))
}
prov(2)\$counts
19 9

This contradicts the help page info, since that implies that the gradient
is called at least as many times as the function.
No, the other way around. It meant `if gr is called, it will be called
...'
I guessed that, which means that it would be possible to do what I want,
given that...
[...]
You need to cache the par values and the results you need, and test both.
... I understand what you mean here. How is it done in my 'trivial
example'?

In my 'real' application, the function and gradient evaluations takes a
long time, but to do both in one call takes almost the same time as just
doing the gradient. So I guess it could be worthwhile to try...

G?ran
[...]

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
•  at Mar 20, 2002 at 4:42 pm ⇧

On Wed, Mar 20, 2002 at 02:31:03PM +0100, G?ran Brostr?m wrote:
I want to maximise a function using 'optim' with a method that requires
the gradient, so I supply two functions, 'fun' for the function value
and 'd.fun' for its gradient. My question is: Since some calculations are
common to the two functions, is it possible to save time by feeding
'd.fun' with some of the calculations made in 'fun'? That would require
(at least) that it is guaranteed that each time 'd.fun' is evaluated, it
is done immediately after a call to 'fun' at the same parameter value.
The help page says:

"It is guaranteed that `gr' will be called immediately after a
call to `fn' at the same parameter values."

which is not exactly the same. However, look at this trivial example:

prov <- function(x.start = 0){
fun <- function(x) {
e.x <- exp(-x)
x * e.x
}
d.fun <- function(x) {
e.x <- exp(-x)
e.x * (1 - x)
}
optim(x.start, fun, d.fun, method = "BFGS",
control = list(fnscale = -1))
}
prov(2)\$counts
19 9

This contradicts the help page info, since that implies that the gradient
is called at least as many times as the function.

Q1: What is the correct guarantee? Is it what I need?

Q2: If so, How do I share calculations between the two functions? In my
trivial example, exp(-x) is calculated in both.

Thanks for any enlightenment! (Brian?)

G?ran
--
G?ran Brostr?m tel: +46 90 786 5223
professor fax: +46 90 786 6614
Department of Statistics http://www.stat.umu.se/egna/gb/
Ume? University
SE-90187 Ume?, Sweden e-mail: gb at stat.umu.se

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

Here is a (proposal of) reply for Q2:

Storing and accessing the result of the 'shared calculation' in a given environment could be a workaround.

Hopin' it helps,

Laurent

--------------------------------------------------------------
Laurent Gautier CBS, Building 208, DTU
PhD. Student D-2800 Lyngby,Denmark
tel: +45 45 25 24 85 http://www.cbs.dtu.dk/laurent
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
•  at Mar 20, 2002 at 4:47 pm ⇧
Hi G?ran,

Q1: first, it seems that the validity of this guarantee depends on the "method" used. Using method="L-BFGS-B", I found that that guarantee seemed to hold for the iterations towards the optimum, but was violated for the final evaluation of the hessian. After submitting a bug report it appears that the documentation will be updated in version 1.5.

Q2: You can use e.g. a variable local to prov() which is visible both to fun() and d.fun(), manipulating it with "<<-" in fun(). Given the uncertainty about this guarantee, it seems advisable to also store the fun() parameters in there, and explicitely verify in d.fun() whether the parameters are really the same...

Best regards,
Wolfgang.

Dr. Wolfgang Huber
DKFZ
Dep. Molecular Genome Analysis
69120 Heidelberg
Germany
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
•  at Mar 20, 2002 at 4:56 pm ⇧

On Wed, 20 Mar 2002, Wolfgang Huber wrote:
Hi G?ran,

Q1: first, it seems that the validity of this guarantee depends on the "method" used. Using method="L-BFGS-B", I found that that guarantee seemed to hold for the iterations towards the optimum, but was violated for the final evaluation of the hessian. After submitting a bug report it appears that the documentation will be updated in version 1.5.

Q2: You can use e.g. a variable local to prov() which is visible both to
fun() and d.fun(), manipulating it with "<<-" in fun(). Given the
fun() parameters in there, and explicitely verify in d.fun() whether the
parameters are really the same...
Yes, that should work! I had totally erased "<<-" from my
R-knowledge-database after all the condemnations of its use I have read
on this very list. Maybe this is an exception...?

Thanks,

G?ran
Best regards,
Wolfgang.

Dr. Wolfgang Huber
DKFZ
Dep. Molecular Genome Analysis
69120 Heidelberg
Germany
--
G?ran Brostr?m tel: +46 90 786 5223
professor fax: +46 90 786 6614
Department of Statistics http://www.stat.umu.se/egna/gb/
Ume? University
SE-90187 Ume?, Sweden e-mail: gb at stat.umu.se

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
•  at Mar 21, 2002 at 8:13 am ⇧

Date: Wed, 20 Mar 2002 14:31:03 +0100 (CET)
From: =?iso-8859-1?Q?Göran_Broström?= <gb@stat.umu.se>
Subject: [R] optim with gradient

I want to maximise a function using 'optim' with a method that requires
the gradient, so I supply two functions, 'fun' for the function value
and 'd.fun' for its gradient. My question is: Since some calculations are
common to the two functions, is it possible to save time by feeding
'd.fun' with some of the calculations made in 'fun'? That would require
(at least) that it is guaranteed that each time 'd.fun' is evaluated, it
is done immediately after a call to 'fun' at the same parameter value.
The help page says:

"It is guaranteed that `gr' will be called immediately after a
call to `fn' at the same parameter values."

which is not exactly the same. However, look at this trivial example:

prov <- function(x.start = 0){
fun <- function(x) {
e.x <- exp(-x)
x * e.x
}
d.fun <- function(x) {
e.x <- exp(-x)
e.x * (1 - x)
}
optim(x.start, fun, d.fun, method = "BFGS",
control = list(fnscale = -1))
}
prov(2)\$counts
19 9

This contradicts the help page info, since that implies that the gradient
is called at least as many times as the function.

Q1: What is the correct guarantee? Is it what I need?

Q2: If so, How do I share calculations between the two functions? In my
trivial example, exp(-x) is calculated in both.

Thanks for any enlightenment! (Brian?)

G?ran
- --
G?ran Brostr?m tel: +46 90 786 5223
professor fax: +46 90 786 6614
Department of Statistics http://www.stat.umu.se/egna/gb/
Ume? University
SE-90187 Ume?, Sweden e-mail: gb at stat.umu.se
If the only goal is to improve speed, then you should consider to do the full optimization within C/Fortran, i.e., to implement the errfunc and the gradient in C and to call optim through the API (a new feature of the upcoming version 1.5.0 as Brian told me). This may increase speed - I just make a rough guess now - by a factor 100.

best

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
•  at Mar 21, 2002 at 10:09 am ⇧
On Thu, 21 Mar 2002, Adrian Trapletti wrote:

[...]
If the only goal is to improve speed, then you should consider to do
the full optimization within C/Fortran, i.e., to implement the errfunc
and the gradient in C and to call optim through the API (a new feature
of the upcoming version 1.5.0 as Brian told me). This may increase speed
- I just make a rough guess now - by a factor 100.
I can hardly wait! I already make the heavy calculations in Fortran, so it
should be easy to implement. Is the feature in R-devel now?
And documented?

Thanks,

G?ran

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
•  at Mar 21, 2002 at 10:56 am ⇧
"GB" == G?ran Brostr?m <gb@stat.umu.se> writes:
GB> On Thu, 21 Mar 2002, Adrian Trapletti wrote: [...]
If the only goal is to improve speed, then you should
consider to do the full optimization within C/Fortran,
i.e., to implement the errfunc and the gradient in C and
to call optim through the API (a new feature of the
upcoming version 1.5.0 as Brian told me). This may
increase speed - I just make a rough guess now - by a
factor 100.
GB> I can hardly wait! I already make the heavy calculations
GB> in Fortran, so it should be easy to implement. Is the
GB> feature in R-devel now? And documented?

2 x yes;
actually for several weeks now (thanks to Brian, of course).

(Apart from the source code,) the documentation is in
the ``Writing Extensions for R'' Manual the latest R-devel
version of which is usually available from
http://stat.ethz.ch/R-alpha/R-devel/doc/html/

Martin
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
•  at Mar 21, 2002 at 11:00 am ⇧

G?ran Brostr?m wrote:

On Thu, 21 Mar 2002, Adrian Trapletti wrote:

[...]
If the only goal is to improve speed, then you should consider to do
the full optimization within C/Fortran, i.e., to implement the errfunc
and the gradient in C and to call optim through the API (a new feature
of the upcoming version 1.5.0 as Brian told me). This may increase speed
- I just make a rough guess now - by a factor 100.
I can hardly wait! I already make the heavy calculations in Fortran, so it
should be easy to implement.
I am not sure what you mean by doing the heavy calculations in Fortran. But I

guess the errfunc (and gradient) are defined in R and itself call Fortran
code using .Fortran()? That?s already more performant, but also then you
should avoid that optim calls an R function. It completely "destroys" the
performance.
Is the feature in R-devel now? Yes.
And documented?
I don?t know. Ask Brian. But I think it should be pretty easy to figure out
how to call optim and how optim calls your functions from the header file.

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

## Related Discussions

 view thread | post
Discussion Overview
 group r-help categories r posted Mar 20, '02 at 7:41a active Mar 21, '02 at 11:00a posts 15 users 11 website r-project.org irc #r

### 11 users in discussion

Content

People

Support

Translate

site design / logo © 2017 Grokbase