Commit 74582e5e authored by Radford Neal's avatar Radford Neal

implement gradient for dpois

parent b7117762
......@@ -152,6 +152,7 @@ gamma, lgamma, digamma, trigamma, beta, lbeta \cr
runif \cr
dexp, rexp \cr
dgeom \cr
dpois \cr
rcauchy \cr
dnorm, rnorm \cr
rlnorm \cr
......
......@@ -2518,10 +2518,10 @@ static void Ddexp (double x, double scale, double *dx, double *dscale,
}
}
static void Ddgeom (double x, double p, double *dx /*ignored*/, double *dp,
double v, int give_log)
static void Ddgeom (double x, double p, double *dx /*ignored*/,
double *dp, double v, int give_log)
{
if (dp == 0) return;
if (!dp) return;
if (x < 0 || p <= 0 || p >= 1)
*dp = 0;
......@@ -2532,6 +2532,20 @@ static void Ddgeom (double x, double p, double *dx /*ignored*/, double *dp,
}
}
static void Ddpois (double x, double lambda, double *dx /*ignored*/,
double *dlambda, double v, int give_log)
{
if (!dlambda) return;
if (x < 0 || lambda < 0)
*dlambda = 0;
else {
*dlambda = x == 0 ? -1 : x/lambda - 1;
if (!give_log)
*dlambda *= v;
}
}
/* Allocate work array for Bessel functions. */
static double *Bessel_work_array (int n2, double *ap2)
......@@ -2555,8 +2569,8 @@ static struct { double (*fncall)(); void (*Dcall)(); } math2_table[31] = {
{ atan2, Datan2 },
{ lbeta, Dlbeta },
{ beta, Dbeta },
{ lchoose, 0 },
{ choose, 0 },
{ lchoose, 0 /* could differentiate wrt 1st arg, but usually integer */ },
{ choose, 0 /* could differentiate wrt 1st arg, but usually integer */ },
{ dchisq, 0 },
{ pchisq, 0 },
{ qchisq, 0 },
......@@ -2566,7 +2580,7 @@ static struct { double (*fncall)(); void (*Dcall)(); } math2_table[31] = {
{ dgeom, Ddgeom },
{ pgeom, 0 },
{ qgeom, 0 },
{ dpois, 0 },
{ dpois, Ddpois },
{ ppois, 0 },
{ qpois, 0 },
{ dt, 0 },
......
......@@ -287,6 +287,9 @@ test1r(rexp)
test2i(dgeom)
test2i(dgeom,log=TRUE)
test2i(dpois)
test2i(dpois,log=TRUE)
test2r(rcauchy)
test2r(rlnorm)
......
......@@ -609,6 +609,15 @@ r2 0.001044058 -0.02858399
r1 -6.86464 -27.37777
r2 -6.86464 -27.37777
>
> test2i(dpois)
[,1] [,2]
r1 0.04879083 0.114805
r2 0.04879083 0.114805
> test2i(dpois,log=TRUE)
[,1] [,2]
r1 -3.020213 2.353004
r2 -3.020213 2.353004
>
> test2r(rcauchy)
x1 x2
r1 -1.585831 1 -2.305762
......
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