Re: [R] Derivative of expm function

2014-04-24 Thread Martin Maechler
 Wagner Bonat wbo...@gmail.com
 on Wed, 23 Apr 2014 12:12:17 +0200 writes:

 Hi all !
 I am look for some efficient method to compute the derivative of
 exponential matrix function in R. For example, I have a simple matrix like

 log.Sigma  - matrix(c(par1, rho, rho, par2),2,2)

 require(Matrix)
 Sigma - expm(log.Sigma)

 I want some method to compute the derivatives of Sigma in relation the
 parameters par1, par2 and rho. Some idea ?

The  'expm' package has slightly newer / more reliable
algorithms for the matrix exponential.

It also contains an  expmFrechet()  function
which computes the Frechet derivative of the matrix exponential.

I'm pretty confident -- but did not start thinking more deeply --
that this should provide the necessary parts to get
partial derivatives like yours as well.

Martin Maechler, ETH Zurich

 Wagner Hugo Bonat
 LEG - Laboratório de Estatística e Geoinformação
 UFPR - Universidade Federal do Paraná

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Derivative of expm function

2014-04-23 Thread Wagner Bonat
Hi all !

I am look for some efficient method to compute the derivative of
exponential matrix function in R. For example, I have a simple matrix like

log.Sigma  - matrix(c(par1, rho, rho, par2),2,2)

require(Matrix)
Sigma - expm(log.Sigma)

I want some method to compute the derivatives of Sigma in relation the
parameters par1, par2 and rho. Some idea ?

-- 
Wagner Hugo Bonat
LEG - Laboratório de Estatística e Geoinformação
UFPR - Universidade Federal do Paraná

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Derivative of a function

2011-06-29 Thread Lisa
This is not a homework. I just want to see if there are some R functions or
some ideas I can borrow to solve my problem. 

--
View this message in context: 
http://r.789695.n4.nabble.com/Derivative-of-a-function-tp3631814p3633071.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Derivative of a function

2011-06-29 Thread David Winsemius


On Jun 29, 2011, at 10:48 AM, Lisa wrote:

This is not a homework. I just want to see if there are some R  
functions or

some ideas I can borrow to solve my problem.


There is a deriv function that provides limited support for symbolic  
differentiation.


The Rhelp list is advertised ( http://www.R-project.org/posting-guide.html 
 ) as expecting you to have made some efforts at searching. This  
answer might not have floated to the surface among the thousand or so  
hits, but at least you should have tried.


RSiteSearch(derivative)

And there is, of course, CrossValidated: http://stats.stackexchange.com/



--
View this message in context: 
http://r.789695.n4.nabble.com/Derivative-of-a-function-tp3631814p3633071.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


David Winsemius, MD
West Hartford, CT

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Derivative of a function

2011-06-29 Thread Gabor Grothendieck
On Tue, Jun 28, 2011 at 10:03 PM, Lisa lisa...@gmail.com wrote:
 Dear all,

 I just want to get the derivative of a function that looks like:

 y = exp(x1*b) / (exp(x1*b) + exp(x2*b))

 where y is a scalar, x1, x2, and b are vectors. I am going to take the
 derivative of b with respect to y, but I cannot derive an expression in
 which b is function of y. I know there is another way to get the similar
 result, i.e., first take the derivative of y with respect to each element of
 b, and then take its reciprocal. But it is not what I want. Could someone
 please tell me how to solve this problem? Thank you in advance.

Assuming you meant the derivative of y with respect to b:

 D(expression(exp(x1*b) / (exp(x1*b) + exp(x2*b))), b)
exp(x1 * b) * x1/(exp(x1 * b) + exp(x2 * b)) - exp(x1 * b) *
(exp(x1 * b) * x1 + exp(x2 * b) * x2)/(exp(x1 * b) + exp(x2 *
b))^2

See ?D and also note deriv on the same help page for another alternative.

-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Derivative of a function

2011-06-29 Thread Rolf Turner

On 30/06/11 06:16, Gabor Grothendieck wrote:

On Tue, Jun 28, 2011 at 10:03 PM, Lisalisa...@gmail.com  wrote:

Dear all,

I just want to get the derivative of a function that looks like:

y = exp(x1*b) / (exp(x1*b) + exp(x2*b))

where y is a scalar, x1, x2, and b are vectors. I am going to take the
derivative of b with respect to y, but I cannot derive an expression in
which b is function of y. I know there is another way to get the similar
result, i.e., first take the derivative of y with respect to each element of
b, and then take its reciprocal. But it is not what I want. Could someone
please tell me how to solve this problem? Thank you in advance.

Assuming you meant the derivative of y with respect to b:


I think the original post made it quite clear that the derivative of b
with respect to y was indeed what was wanted; i.e. the OP needs to
do implicit differentiation which R does not do automatically.

cheers,

Rolf Turner

D(expression(exp(x1*b) / (exp(x1*b) + exp(x2*b))), b)

exp(x1 * b) * x1/(exp(x1 * b) + exp(x2 * b)) - exp(x1 * b) *
 (exp(x1 * b) * x1 + exp(x2 * b) * x2)/(exp(x1 * b) + exp(x2 *
 b))^2

See ?D and also note deriv on the same help page for another alternative.



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Derivative of a function

2011-06-29 Thread Lisa
Yes. I need to do implicit differentiation. After rearrangement, I got 

(x2 – x1) * b = log(1 / y - 1)

Take derivative of both sides with respect to y, I have

(x2 – x1) * b’[y] = - 1/y(1-y)

Since both (x2 – x1) and b’[y] are vectors, I cannot move (x2 – x1) to
RHS. This is why I posted my question here to see if there is some R
functions or some idea that can help me solve this problem. Thanks.

Lisa


--
View this message in context: 
http://r.789695.n4.nabble.com/Derivative-of-a-function-tp3631814p3633947.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Derivative of a function

2011-06-29 Thread Gabor Grothendieck
On Wed, Jun 29, 2011 at 4:35 PM, Lisa lisa...@gmail.com wrote:
 Yes. I need to do implicit differentiation. After rearrangement, I got

 (x2 – x1) * b = log(1 / y - 1)

 Take derivative of both sides with respect to y, I have

 (x2 – x1) * b’[y] = - 1/y(1-y)

 Since both (x2 – x1) and b’[y] are vectors, I cannot move (x2 – x1) to
 RHS. This is why I posted my question here to see if there is some R
 functions or some idea that can help me solve this problem. Thanks.


I am not sure if this counts as an approach that you are trying to exclude but:

db[i]/dy = { dlogit(y)/dy } / { dlogit(y)/db[i] } = { 1/{y(1-y)} / {
x1[i] - x2[i] }

The numerator is taken from your calculation and the denominator is
from linearity.

-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Derivative of a function

2011-06-29 Thread S Ellison
If you just want the value of the derivative at a particular point, would 
numerical derivatives suffice? If so, try (for example) the numDeriv package.

S

From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On Behalf Of 
Lisa [lisa...@gmail.com]
Sent: 29 June 2011 21:35
To: r-help@r-project.org
Subject: Re: [R] Derivative of a function

Yes. I need to do implicit differentiation. After rearrangement, I got

(x2 – x1) * b = log(1 / y - 1)

Take derivative of both sides with respect to y, I have

(x2 – x1) * b’[y] = - 1/y(1-y)

Since both (x2 – x1) and b’[y] are vectors, I cannot move (x2 – x1) to
RHS. This is why I posted my question here to see if there is some R
functions or some idea that can help me solve this problem. Thanks.

Lisa


--
View this message in context: 
http://r.789695.n4.nabble.com/Derivative-of-a-function-tp3631814p3633947.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
***
This email and any attachments are confidential. Any use...{{dropped:8}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Derivative of a function

2011-06-28 Thread Lisa
Dear all,

I just want to get the derivative of a function that looks like:

y = exp(x1*b) / (exp(x1*b) + exp(x2*b))

where y is a scalar, x1, x2, and b are vectors. I am going to take the
derivative of b with respect to y, but I cannot derive an expression in
which b is function of y. I know there is another way to get the similar
result, i.e., first take the derivative of y with respect to each element of
b, and then take its reciprocal. But it is not what I want. Could someone
please tell me how to solve this problem? Thank you in advance. 

Lisa


--
View this message in context: 
http://r.789695.n4.nabble.com/Derivative-of-a-function-tp3631814p3631814.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Derivative of a function

2011-06-28 Thread Rolf Turner


(1) You really ought to do your own homework.

(2) What has this to do with R?

cheers,

Rolf Turner

On 29/06/11 14:03, Lisa wrote:

Dear all,

I just want to get the derivative of a function that looks like:

y = exp(x1*b) / (exp(x1*b) + exp(x2*b))

where y is a scalar, x1, x2, and b are vectors. I am going to take the
derivative of b with respect to y, but I cannot derive an expression in
which b is function of y. I know there is another way to get the similar
result, i.e., first take the derivative of y with respect to each element of
b, and then take its reciprocal. But it is not what I want. Could someone
please tell me how to solve this problem? Thank you in advance.

Lisa


--
View this message in context: 
http://r.789695.n4.nabble.com/Derivative-of-a-function-tp3631814p3631814.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.