Re: [Rd] Wish List: Extensions to the derivatives table

2017-02-20 Thread Martin Maechler
> 
> The issue is that without an extensible derivative table or the proposed 
> extensions, it is not possible to automatically produce (without manual 
> modification of the deriv3 output) a function that avoids catastrophic 
> cancellation regardless of the working range.
> Manual modification is not onerous as a one-time exercise, but can be time 
> consuming when it must be done numerous times, for example when evaluating 
> the impact of different parameterizations on parameter effects curvature.  
> The alternative of more flexible differentiation does not seem to be a 
> difficult addition to R.  In S+ (which does not have deriv3) it would simply 
> involve adding the following lines to the switch statement in D
> 
>   expm1 = make.call("*", make.call("exp", expr[[2]]), D(expr[[2]], name)),
>   log1p = make.call("/", D(expr[[2]], name), make.call("+", 1., expr[[2]])),
>   log2 = make.call("/", make.call("/", D(expr[[2]], name), expr[[2]]), 
> quote(log(2)) ),
>   log10 = make.call("/", make.call("/", D(expr[[2]], name), expr[[2]]), 
> quote(log(10)) ),
>   cospi = make.call("*", make.call("*", make.call("sinpi", expr[[2]]), 
> make.call("-", D(expr[[2]], name))), quote(pi)),
>   sinpi = make.call("*", make.call("*", make.call("cospi", expr[[2]]), 
> D(expr[[2]], name)), quote(pi)),
>   tanpi = make.call("/", make.call("*", D(expr[[2]], name), quote(pi)), 
> make.call("^", make.call("cospi", expr[[2]]), 2)),
> 
> Jerry

You are right, Jerry, it would be nice if R's derivative table
could be extended by the useR  using simple R code.
As Duncan Murdoch has mentioned already, this is now provided as
a byproduct of the functionality in the CRAN package 'nlsr'
{after that is tweaked, as you mentioned}, which is nice and
good to know (for all of us).

As one person who knows how important it may be to avoid cancellation,
I still would be willing to add to the "derivatives table" in
R's C source  if people like you provided  a (tested!) patch to
the source, which is in
https://svn.r-project.org/R/trunk/src/library/stats/src/deriv.c

Martin


> From: Avraham Adler [mailto:avraham.ad...@gmail.com]
> Sent: Friday, February 17, 2017 4:16 PM
> To: Jerry Lewis; r-devel@r-project.org
> Subject: Re: [Rd] Wish List: Extensions to the derivatives table
> 
> Hi.
> 
> Unless I'm misremembering, log, exp, sin, cos, and tan are all handled in 
> deriv3. The functions listed are  specially coded slightly more accurate 
> versions but can be substituted with native ones for which deriv/deriv3 will 
> work automatically. I believe that if you  write your functions using log(a + 
> 1) instead of log1p(a) or log(x) / log(2) instead of log2(x) deriv3 will work 
> fine.


> Thanks,
> Avi
> 
> On Fri, Feb 17, 2017 at 2:02 PM Jerry Lewis 
> <jerry.le...@biogen.com<mailto:jerry.le...@biogen.com>> wrote:
> The derivative table resides in the function D.  In S+ that table is 
> extensible because it is written in the S language.  R is faster but less 
> flexible, since that table is programmed in C.  It would be useful if R 
> provided a mechanism for extending the derivative table, or barring that, 
> provided a broader table.  Currently unsupported mathematical functions of 
> one argument include expm1, log1p, log2, log10, cospi, sinpi, and tanpi.
> 
> While manual differentiation of these proposed additions is straight-forward, 
> their absence complicates what otherwise could be much simpler, such as using 
> deriv() or deriv3() to generate functions, for example to use as an nls model.
> 
> Thanks,

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Wish List: Extensions to the derivatives table

2017-02-17 Thread Jerry Lewis
Thank you.  The nlsr package will be a satisfactory alternative once the bug in 
fnDeriv(..., hessian=TRUE) is patched.  I have notified the maintainer.

Jerry

-Original Message-
From: Duncan Murdoch [mailto:murdoch.dun...@gmail.com] 
Sent: Friday, February 17, 2017 6:05 PM
To: Jerry Lewis; r-devel@r-project.org
Subject: Re: [Rd] Wish List: Extensions to the derivatives table

On 17/02/2017 1:59 PM, Jerry Lewis wrote:
> The derivative table resides in the function D.  In S+ that table is 
> extensible because it is written in the S language.  R is faster but less 
> flexible, since that table is programmed in C.  It would be useful if R 
> provided a mechanism for extending the derivative table, or barring that, 
> provided a broader table.  Currently unsupported mathematical functions of 
> one argument include expm1, log1p, log2, log10, cospi, sinpi, and tanpi.
>
> While manual differentiation of these proposed additions is straight-forward, 
> their absence complicates what otherwise could be much simpler, such as using 
> deriv() or deriv3() to generate functions, for example to use as an nls model.

The nlsr package allows you to specify derivatives.

Duncan Murdoch

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Wish List: Extensions to the derivatives table

2017-02-17 Thread Jerry Lewis
The issue is that without an extensible derivative table or the proposed 
extensions, it is not possible to automatically produce (without manual 
modification of the deriv3 output) a function that avoids catastrophic 
cancellation regardless of the working range.

Manual modification is not onerous as a one-time exercise, but can be time 
consuming when it must be done numerous times, for example when evaluating the 
impact of different parameterizations on parameter effects curvature.  The 
alternative of more flexible differentiation does not seem to be a difficult 
addition to R.  In S+ (which does not have deriv3) it would simply involve 
adding the following lines to the switch statement in D

  expm1 = make.call("*", make.call("exp", expr[[2]]), D(expr[[2]], name)),
  log1p = make.call("/", D(expr[[2]], name), make.call("+", 1., expr[[2]])),
  log2 = make.call("/", make.call("/", D(expr[[2]], name), expr[[2]]), 
quote(log(2)) ),
  log10 = make.call("/", make.call("/", D(expr[[2]], name), expr[[2]]), 
quote(log(10)) ),
  cospi = make.call("*", make.call("*", make.call("sinpi", expr[[2]]), 
make.call("-", D(expr[[2]], name))), quote(pi)),
  sinpi = make.call("*", make.call("*", make.call("cospi", expr[[2]]), 
D(expr[[2]], name)), quote(pi)),
  tanpi = make.call("/", make.call("*", D(expr[[2]], name), quote(pi)), 
make.call("^", make.call("cospi", expr[[2]]), 2)),

Jerry

From: Avraham Adler [mailto:avraham.ad...@gmail.com]
Sent: Friday, February 17, 2017 4:16 PM
To: Jerry Lewis; r-devel@r-project.org
Subject: Re: [Rd] Wish List: Extensions to the derivatives table

Hi.

Unless I'm misremembering, log, exp, sin, cos, and tan are all handled in 
deriv3. The functions listed are  specially coded slightly more accurate 
versions but can be substituted with native ones for which deriv/deriv3 will 
work automatically. I believe that if you  write your functions using log(a + 
1) instead of log1p(a) or log(x) / log(2) instead of log2(x) deriv3 will work 
fine.

Thanks,

Avi

On Fri, Feb 17, 2017 at 2:02 PM Jerry Lewis 
<jerry.le...@biogen.com<mailto:jerry.le...@biogen.com>> wrote:
The derivative table resides in the function D.  In S+ that table is extensible 
because it is written in the S language.  R is faster but less flexible, since 
that table is programmed in C.  It would be useful if R provided a mechanism 
for extending the derivative table, or barring that, provided a broader table.  
Currently unsupported mathematical functions of one argument include expm1, 
log1p, log2, log10, cospi, sinpi, and tanpi.

While manual differentiation of these proposed additions is straight-forward, 
their absence complicates what otherwise could be much simpler, such as using 
deriv() or deriv3() to generate functions, for example to use as an nls model.

Thanks,

[[alternative HTML version deleted]]

__
R-devel@r-project.org<mailto:R-devel@r-project.org> mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel<https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_r-2Ddevel=DwMFaQ=n7UHtw8cUfEZZQ61ciL2BA=xs_tXUrv91YrLJDF556854t-QoeZJZaWm9FEXA9zM5g=-A1aEBZHHGplCfEF7yE3w1qkXptmiyra-em-DMThcAU=GJ4FysAkXSzYkfhgXMcAnPtGKT6syHkLAJp9JtkLVik=>
--
Sent from Gmail Mobile

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Wish List: Extensions to the derivatives table

2017-02-17 Thread Avraham Adler
Hi.

Unless I'm misremembering, log, exp, sin, cos, and tan are all handled in
deriv3. The functions listed are  specially coded slightly more accurate
versions but can be substituted with native ones for which deriv/deriv3
will work automatically. I believe that if you  write your functions using
log(a + 1) instead of log1p(a) or log(x) / log(2) instead of log2(x) deriv3
will work fine.

Thanks,

Avi

On Fri, Feb 17, 2017 at 2:02 PM Jerry Lewis  wrote:

> The derivative table resides in the function D.  In S+ that table is
> extensible because it is written in the S language.  R is faster but less
> flexible, since that table is programmed in C.  It would be useful if R
> provided a mechanism for extending the derivative table, or barring that,
> provided a broader table.  Currently unsupported mathematical functions of
> one argument include expm1, log1p, log2, log10, cospi, sinpi, and tanpi.
>
> While manual differentiation of these proposed additions is
> straight-forward, their absence complicates what otherwise could be much
> simpler, such as using deriv() or deriv3() to generate functions, for
> example to use as an nls model.
>
> Thanks,
>
> [[alternative HTML version deleted]]
>
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
-- 
Sent from Gmail Mobile

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Wish List: Extensions to the derivatives table

2017-02-17 Thread Jerry Lewis
The derivative table resides in the function D.  In S+ that table is extensible 
because it is written in the S language.  R is faster but less flexible, since 
that table is programmed in C.  It would be useful if R provided a mechanism 
for extending the derivative table, or barring that, provided a broader table.  
Currently unsupported mathematical functions of one argument include expm1, 
log1p, log2, log10, cospi, sinpi, and tanpi.

While manual differentiation of these proposed additions is straight-forward, 
their absence complicates what otherwise could be much simpler, such as using 
deriv() or deriv3() to generate functions, for example to use as an nls model.

Thanks,

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel