Commit 2b0256a6 authored by Radford Neal's avatar Radford Neal

implement derivatives for dlogis

parent dc344724
......@@ -2846,6 +2846,57 @@ static void Dqnorm (double p, double mu, double sigma,
}
}
static void Ddlogis (double x, double location, double scale,
double *dx, double *dlocation, double *dscale,
int give_log, double v)
{
if (!R_FINITE(v)) {
if (dx) *dx = 0;
if (dlocation) *dlocation = 0;
if (dscale) *dscale = 0;
}
else {
double x0 = (x - location) / scale;
double t = tanh(x0/2);
if (give_log) {
if (dx) *dx = - t / scale;
if (dlocation) *dlocation = t / scale;
if (dscale) *dscale = (t*x0 - 1) / scale;
}
else {
if (dx) *dx = - v * t / scale;
if (dlocation) *dlocation = v * t / scale;
if (dscale) *dscale = v * (t*x0 - 1) / scale;
}
}
}
static void Dplogis (double q, double location, double scale,
double *dq, double *dlocation, double *dscale,
int lower_tail, int log_p, double v)
{
if (scale <= 0) {
if (dq) *dq = 0;
if (dlocation) *dlocation = 0;
if (dscale) *dscale = 0;
}
else {
}
}
static void Dqlogis (double p, double location, double scale,
double *dp, double *dlocation, double *dscale,
int lower_tail, int log_p, double v)
{
if (scale <= 0) {
if (dp) *dp = 0;
if (dlocation) *dlocation = 0;
if (dscale) *dscale = 0;
}
else {
}
}
/* Table of functions to compute values and derivatives for math3 functions. */
static struct { double (*fncall)(); void (*Dcall)(); } math3_table[48] = {
......@@ -2868,7 +2919,7 @@ static struct { double (*fncall)(); void (*Dcall)(); } math3_table[48] = {
{ dlnorm, 0 },
{ plnorm, 0 },
{ qlnorm, 0 },
{ dlogis, 0 },
{ dlogis, Ddlogis },
{ plogis, 0 },
{ qlogis, 0 },
{ dnbinom, 0 },
......
......@@ -328,6 +328,11 @@ test2r(rcauchy)
test2r(rlnorm)
test3(dlogis)
test3(dlogis,log=TRUE)
test3z(dlogis)
test3z(dlogis,log=TRUE)
test2r(rlogis)
test3(dnorm)
......
......@@ -662,6 +662,59 @@ r2 -1.585831 1 -2.305762
r1 2.16995 2.16995 0.7215801
r2 2.16995 2.16995 0.7215800
>
> test3(dlogis)
[,1] [,2]
r1 0.3377968 0.1507839
r2 0.3377968 0.1507838
[,1] [,2]
r1 0.3377968 -0.1507838
r2 0.3377968 -0.1507838
[,1] [,2]
r1 0.3377968 -0.4082265
r2 0.3377968 -0.4082265
x1 x2 x3
r1 0.3377968 0.1507839 -0.1507838 -0.4082265
r2 0.3377968 0.1507838 -0.1507838 -0.4082265
> test3(dlogis,log=TRUE)
[,1] [,2]
r1 -1.085311 0.4463744
r2 -1.085311 0.4463744
[,1] [,2]
r1 -1.085311 -0.4463744
r2 -1.085311 -0.4463744
[,1] [,2]
r1 -1.085311 -1.208497
r2 -1.085311 -1.208497
x1 x2 x3
r1 -1.085311 0.4463744 -0.4463744 -1.208497
r2 -1.085311 0.4463744 -0.4463744 -1.208497
> test3z(dlogis)
[,1] [,2]
r1 0.03679051 0.0006876616
r2 0.03679051 0.0006876617
[,1] [,2]
r1 0.03679051 -0.0006876618
r2 0.03679051 -0.0006876617
[,1] [,2]
r1 0.03679051 -0.005327287
r2 0.03679051 -0.005327288
z1 z2 z3
r1 0.03679051 0.0006876616 -0.0006876618 -0.005327287
r2 0.03679051 0.0006876617 -0.0006876617 -0.005327288
> test3z(dlogis,log=TRUE)
[,1] [,2]
r1 -3.302515 0.01869128
r2 -3.302515 0.01869128
[,1] [,2]
r1 -3.302515 -0.01869128
r2 -3.302515 -0.01869128
[,1] [,2]
r1 -3.302515 -0.1448006
r2 -3.302515 -0.1448006
z1 z2 z3
r1 -3.302515 0.01869128 -0.01869128 -0.1448006
r2 -3.302515 0.01869128 -0.01869128 -0.1448006
>
> test2r(rlogis)
x1 x2
r1 0.9543501 1 0.5333178
......
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