Skip to content

inverted axis

11 messages · Juhana Vartiainen, Ott Toomet, Jason Turner +6 more

#
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
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
instead of seq(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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On Wed, Mar 20, 2002 at 09:41:04AM +0200, Juhana Vartiainen wrote:
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
#
Jason Turner wrote:
Let me add:
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
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:

  
    
#
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))
}
function gradient 
      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
#
On Wed, 20 Mar 2002, [iso-8859-1] Göran Broström wrote:

            
Only if hessian=FALSE, and that phrase is now removed.
No, the other way around.  It meant `if gr is called, it will be called
...'
You need to cache the par values and the results you need, and test both.
It is unlikely to be worth it.

  
    
#
On Wed, 20 Mar 2002 ripley at stats.ox.ac.uk wrote:

            
I guessed that, which means that it would be possible to do what I want, 
given that...
[...]
... 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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On Wed, Mar 20, 2002 at 02:31:03PM +0100, G?ran Brostr?m wrote:
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On Wed, 20 Mar 2002, Wolfgang Huber wrote:

            
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