Commit 2958ae70 authored by Radford Neal's avatar Radford Neal

implement derivative for ppois

parent 3af87e62
......@@ -148,7 +148,7 @@ gamma, lgamma, digamma, trigamma, beta, lbeta \cr
dunif, punif, qunif, runif \cr
dexp, pexp, qexp, rexp \cr
dgeom, pgeom \cr
dpois \cr
dpois, ppois \cr
dbeta \cr
dbinom \cr
pcauchy, qcauchy, rcauchy \cr
......
......@@ -2618,6 +2618,23 @@ static void Ddpois (double x, double lambda, double *dx /*ignored*/,
}
}
static void Dppois (double x, double lambda, double *dx /*ignored*/,
double *dlambda, double v, int lower_tail, int log_p)
{
if (!dlambda) return;
if (x < 0 || lambda < 0)
*dlambda = 0;
else {
double d = dpois(x,lambda,FALSE);
*dlambda = lower_tail ? -d : d;
if (log_p)
*dlambda *= exp(-v);
}
}
/* Allocate work array for Bessel functions. */
static double *Bessel_work_array (int n2, double *ap2)
......@@ -2653,7 +2670,7 @@ static struct { double (*fncall)(); void (*Dcall)(); } math2_table[31] = {
{ pgeom, Dpgeom },
{ qgeom, 0 /* discrete */ },
{ dpois, Ddpois },
{ ppois, 0 },
{ ppois, Dppois },
{ qpois, 0 /* discrete */ },
{ dt, 0 },
{ pt, 0 },
......
......@@ -379,6 +379,11 @@ test2i(pgeom,log=TRUE,lower=FALSE)
test2i(dpois)
test2i(dpois,log=TRUE)
test2i(ppois)
test2i(ppois,log=TRUE)
test2i(ppois,lower=FALSE)
test2i(ppois,log=TRUE,lower=FALSE)
test3(dbeta)
test3(dbeta,log=TRUE)
test3w(dbeta)
......
......@@ -815,6 +815,23 @@ r2 0.04879083 0.114805
r1 -3.020213 2.353004
r2 -3.020213 2.353004
>
> test2i(ppois)
[,1] [,2]
r1 0.9868005 -0.04879083
r2 0.9868005 -0.04879083
> test2i(ppois,log=TRUE)
[,1] [,2]
r1 -0.01328739 -0.04944346
r2 -0.01328739 -0.04944346
> test2i(ppois,lower=FALSE)
[,1] [,2]
r1 0.0131995 0.04879083
r2 0.0131995 0.04879083
> test2i(ppois,log=TRUE,lower=FALSE)
[,1] [,2]
r1 -4.327576 3.696414
r2 -4.327576 3.696414
>
> test3(dbeta)
[,1] [,2]
r1 0.8258716 0.3339383
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment