Commit 438b45f3 authored by Radford Neal's avatar Radford Neal

implemented derivatives for dcauchy

parent 61db35e1
......@@ -151,7 +151,7 @@ dgeom, pgeom \cr
dpois, ppois \cr
dbeta \cr
dbinom \cr
pcauchy, qcauchy, rcauchy \cr
dcauchy, pcauchy, qcauchy, rcauchy \cr
dnorm, pnorm, qnorm, rnorm \cr
rlnorm \cr
dlogis, plogis, qlogis, rlogis \cr
......
......@@ -2900,6 +2900,31 @@ static void Ddbinom (double x, double n, double p,
}
}
static void Ddcauchy (double x, double location, double scale,
double *dx, double *dlocation, double *dscale,
double v, int give_log)
{
if (!R_FINITE(v)) {
if (dx) *dx = 0;
if (dlocation) *dlocation = 0;
if (dscale) *dscale = 0;
}
else {
double x0 = (x - location) / scale;
double f = 1 + x0*x0;
if (give_log) {
if (dx) *dx = -2*x0 / (f*scale);
if (dlocation) *dlocation = 2*x0 / (f*scale);
if (dscale) *dscale = (x0*x0-1) / (f*scale);
}
else {
if (dx) *dx = -2*v*x0 / (f*scale);
if (dlocation) *dlocation = 2*v*x0 / (f*scale);
if (dscale) *dscale = v * (x0*x0-1) / (f*scale);
}
}
}
static void Dpcauchy (double q, double location, double scale,
double *dq, double *dlocation, double *dscale,
double v, int lower_tail, int log_p)
......@@ -3202,7 +3227,7 @@ static struct { double (*fncall)(); void (*Dcall)(); } math3_table[48] = {
{ dbinom, Ddbinom },
{ pbinom, 0 },
{ qbinom, 0 /* discrete */ },
{ dcauchy, 0 },
{ dcauchy, Ddcauchy },
{ pcauchy, Dpcauchy },
{ qcauchy, Dqcauchy },
{ df, 0 },
......
......@@ -392,6 +392,11 @@ test3w(dbeta,log=TRUE)
test3v(dbinom)
test3v(dbinom,log=TRUE)
test3(dcauchy)
test3(dcauchy,log=TRUE)
test3z(dcauchy)
test3z(dcauchy,log=TRUE)
test3(pcauchy)
test3(pcauchy,log=TRUE)
test3(pcauchy,lower=FALSE)
......
......@@ -894,6 +894,59 @@ r2 0.1429615 -0.9814315
r1 -1.94518 -6.865007
r2 -1.94518 -6.865006
>
> test3(dcauchy)
[,1] [,2]
r1 0.3414601 0.4543405
r2 0.3414601 0.4543405
[,1] [,2]
r1 0.3414601 -0.4543405
r2 0.3414601 -0.4543405
[,1] [,2]
r1 0.3414601 -0.2254062
r2 0.3414601 -0.2254062
x1 x2 x3
r1 0.3414601 0.4543405 -0.4543405 -0.2254062
r2 0.3414601 0.4543405 -0.4543405 -0.2254062
> test3(dcauchy,log=TRUE)
[,1] [,2]
r1 -1.074524 1.330582
r2 -1.074524 1.330582
[,1] [,2]
r1 -1.074524 -1.330582
r2 -1.074524 -1.330582
[,1] [,2]
r1 -1.074524 -0.6601247
r2 -1.074524 -0.6601247
x1 x2 x3
r1 -1.074524 1.330582 -1.330582 -0.6601247
r2 -1.074524 1.330582 -1.330582 -0.6601247
> test3z(dcauchy)
[,1] [,2]
r1 0.04475888 0.00316408
r2 0.04475888 0.00316408
[,1] [,2]
r1 0.04475888 -0.00316408
r2 0.04475888 -0.00316408
[,1] [,2]
r1 0.04475888 -0.005896058
r2 0.04475888 -0.005896058
z1 z2 z3
r1 0.04475888 0.00316408 -0.00316408 -0.005896058
r2 0.04475888 0.00316408 -0.00316408 -0.005896058
> test3z(dcauchy,log=TRUE)
[,1] [,2]
r1 -3.106465 0.07069167
r2 -3.106465 0.07069167
[,1] [,2]
r1 -3.106465 -0.07069168
r2 -3.106465 -0.07069167
[,1] [,2]
r1 -3.106465 -0.1317294
r2 -3.106465 -0.1317294
z1 z2 z3
r1 -3.106465 0.07069167 -0.07069168 -0.1317294
r2 -3.106465 0.07069167 -0.07069167 -0.1317294
>
> test3(pcauchy)
[,1] [,2]
r1 0.3232967 0.3414601
......
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