diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/foreign/CallAndExternalFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/foreign/CallAndExternalFunctions.java index 4c14ad345c742ba20d61989ee926d68d34bb0e65..b21920e7d29d04c562819874f32d636b6efa3b5f 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/foreign/CallAndExternalFunctions.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/foreign/CallAndExternalFunctions.java @@ -104,6 +104,7 @@ import com.oracle.truffle.r.runtime.nmath.distr.DPois; import com.oracle.truffle.r.runtime.nmath.distr.Dbinom; import com.oracle.truffle.r.runtime.nmath.distr.Df; import com.oracle.truffle.r.runtime.nmath.distr.Dnf; +import com.oracle.truffle.r.runtime.nmath.distr.Dnt; import com.oracle.truffle.r.runtime.nmath.distr.Dt; import com.oracle.truffle.r.runtime.nmath.distr.Exp.DExp; import com.oracle.truffle.r.runtime.nmath.distr.Exp.PExp; @@ -131,6 +132,7 @@ import com.oracle.truffle.r.runtime.nmath.distr.Pbinom; import com.oracle.truffle.r.runtime.nmath.distr.Pf; import com.oracle.truffle.r.runtime.nmath.distr.Pnf; import com.oracle.truffle.r.runtime.nmath.distr.Pnorm; +import com.oracle.truffle.r.runtime.nmath.distr.Pnt; import com.oracle.truffle.r.runtime.nmath.distr.Pt; import com.oracle.truffle.r.runtime.nmath.distr.QBeta; import com.oracle.truffle.r.runtime.nmath.distr.QGamma; @@ -144,6 +146,7 @@ import com.oracle.truffle.r.runtime.nmath.distr.Qbinom; import com.oracle.truffle.r.runtime.nmath.distr.Qf; import com.oracle.truffle.r.runtime.nmath.distr.Qnf; import com.oracle.truffle.r.runtime.nmath.distr.Qnorm; +import com.oracle.truffle.r.runtime.nmath.distr.Qnt; import com.oracle.truffle.r.runtime.nmath.distr.Qt; import com.oracle.truffle.r.runtime.nmath.distr.RBeta; import com.oracle.truffle.r.runtime.nmath.distr.RGamma; @@ -465,6 +468,12 @@ public class CallAndExternalFunctions { return StatsFunctionsNodes.Function2_1Node.create(new DSignrank()); case "psignrank": return StatsFunctionsNodes.Function2_2Node.create(new PSignrank()); + case "dnt": + return StatsFunctionsNodes.Function3_1Node.create(new Dnt()); + case "pnt": + return StatsFunctionsNodes.Function3_2Node.create(new Pnt()); + case "qnt": + return StatsFunctionsNodes.Function3_2Node.create(new Qnt()); case "qsignrank": return StatsFunctionsNodes.Function2_2Node.create(new QSignrank()); case "rmultinom": diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/Dnt.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/Dnt.java new file mode 100644 index 0000000000000000000000000000000000000000..9a8731981dd91ac6dc3435074c8e7df2e82fb755 --- /dev/null +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/Dnt.java @@ -0,0 +1,75 @@ +/* + * This material is distributed under the GNU General Public License + * Version 2. You may review the terms of this license at + * http://www.gnu.org/licenses/gpl-2.0.html + * + * Copyright (c) 2003-2015, The R Foundation + * Copyright (c) 2017, Oracle and/or its affiliates + * + * All rights reserved. + */ +/* + * AUTHOR + * Claus Ekstrøm, ekstrom@dina.kvl.dk + * July 15, 2003. + */ +package com.oracle.truffle.r.runtime.nmath.distr; + +import static com.oracle.truffle.r.runtime.nmath.GammaFunctions.lgammafn; +import static com.oracle.truffle.r.runtime.nmath.MathConstants.DBL_EPSILON; +import static com.oracle.truffle.r.runtime.nmath.MathConstants.M_LN_SQRT_PI; + +import com.oracle.truffle.r.runtime.nmath.DPQ; +import com.oracle.truffle.r.runtime.nmath.MathFunctions.Function3_1; +import com.oracle.truffle.r.runtime.nmath.RMathError; +import com.oracle.truffle.r.runtime.nmath.TOMS708; + +public final class Dnt implements Function3_1 { + private final Dt dt = new Dt(); + private final DNorm dnorm = new DNorm(); + private final Pnt pnt = new Pnt(); + + @Override + public double evaluate(double x, double df, double ncp, boolean giveLog) { + if (Double.isNaN(x) || Double.isNaN(df)) { + return x + df; + } + + /* If non-positive df then error */ + if (df <= 0.0) { + return RMathError.defaultError(); + } + + if (ncp == 0.0) { + return dt.evaluate(x, df, giveLog); + } + + /* If x is infinite then return 0 */ + if (!Double.isFinite(x)) { + return DPQ.rd0(giveLog); + } + + /* + * If infinite df then the density is identical to a normal distribution with mean = ncp. + * However, the formula loses a lot of accuracy around df=1e9 + */ + if (!Double.isFinite(df) || df > 1e8) { + return dnorm.evaluate(x, ncp, 1., giveLog); + } + + /* Do calculations on log scale to stabilize */ + + /* Consider two cases: x ~= 0 or not */ + double u; + if (TOMS708.fabs(x) > Math.sqrt(df * DBL_EPSILON)) { + u = Math.log(df) - Math.log(TOMS708.fabs(x)) + + Math.log(TOMS708.fabs(pnt.evaluate(x * Math.sqrt((df + 2) / df), df + 2, ncp, true, false) - + pnt.evaluate(x, df, ncp, true, false))); + /* GnuR fix me: the above still suffers from cancellation (but not horribly) */ + } else { /* x ~= 0 : -> same value as for x = 0 */ + u = lgammafn((df + 1) / 2) - lgammafn(df / 2) - (M_LN_SQRT_PI + .5 * (Math.log(df) + ncp * ncp)); + } + + return (giveLog ? u : Math.exp(u)); + } +} diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/Pnt.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/Pnt.java new file mode 100644 index 0000000000000000000000000000000000000000..d1dc11c6b66f59cb090de6964a06a1a3e48c7cf3 --- /dev/null +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/Pnt.java @@ -0,0 +1,174 @@ +/* + * This material is distributed under the GNU General Public License + * Version 2. You may review the terms of this license at + * http://www.gnu.org/licenses/gpl-2.0.html + * + * Copyright (c) 1998-2015, The R Core Team + * Copyright (c) 2017, Oracle and/or its affiliates + * + * All rights reserved. + */ +/* + * based on AS243 (C) 1989 Royal Statistical Society + */ +package com.oracle.truffle.r.runtime.nmath.distr; + +import static com.oracle.truffle.r.runtime.nmath.GammaFunctions.lgammafn; +import static com.oracle.truffle.r.runtime.nmath.MathConstants.DBL_EPSILON; +import static com.oracle.truffle.r.runtime.nmath.MathConstants.DBL_MIN_EXP; +import static com.oracle.truffle.r.runtime.nmath.MathConstants.M_LN2; +import static com.oracle.truffle.r.runtime.nmath.MathConstants.M_LN_SQRT_PI; +import static com.oracle.truffle.r.runtime.nmath.MathConstants.M_SQRT_2dPI; + +import com.oracle.truffle.r.runtime.nmath.DPQ; +import com.oracle.truffle.r.runtime.nmath.MathFunctions.Function3_2; +import com.oracle.truffle.r.runtime.nmath.RMath; +import com.oracle.truffle.r.runtime.nmath.RMathError; +import com.oracle.truffle.r.runtime.nmath.RMathError.MLError; +import com.oracle.truffle.r.runtime.nmath.TOMS708; + +public class Pnt implements Function3_2 { + private static final int itrmax = 1000; + private static final double errmax = 1.e-12; + + private final Pt pt = new Pt(); + private final Pnorm pnorm = new Pnorm(); + private final Pbeta pbeta = new Pbeta(); + + @Override + public double evaluate(double t, double df, double ncp, boolean lowerTail, boolean logP) { + if (df <= 0.0) { + return RMathError.defaultError(); + } + if (ncp == 0.0) { + return pt.evaluate(t, df, lowerTail, logP); + } + + if (!Double.isFinite(t)) { + return t < 0 ? DPQ.rdt0(lowerTail, logP) : DPQ.rdt1(lowerTail, logP); + } + + boolean negdel; + double tt; + double del; + if (t >= 0.) { + negdel = false; + tt = t; + del = ncp; + } else { + /* + * We deal quickly with left tail if extreme, since pt(q, df, ncp) <= pt(0, df, ncp) = + * \Phi(-ncp) + */ + if (ncp > 40 && (!logP || !lowerTail)) { + return DPQ.rdt0(lowerTail, logP); + } + negdel = true; + tt = -t; + del = -ncp; + } + + /* LDOUBLE */double s; + if (df > 4e5 || del * del > 2 * M_LN2 * (-DBL_MIN_EXP)) { + /*-- 2nd part: if del > 37.62, then p=0 below + GnuR fix me: test should depend on `df', `tt' AND `del' ! */ + /* Approx. from Abramowitz & Stegun 26.7.10 (p.949) */ + s = 1. / (4. * df); + double pnormSigma = Math.sqrt(1. + tt * tt * 2. * s); + return pnorm.evaluate(tt * (1. - s), del, pnormSigma, lowerTail != negdel, logP); + } + + /* initialize twin series */ + /* Guenther, J. (1978). Statist. Computn. Simuln. vol.6, 199. */ + + double x = t * t; + double rxb = df / (x + df); /* := (1 - x) {x below} -- but more accurately */ + x = x / (x + df); /* in [0,1) */ + debugPrintf("pnt(t=%7g, df=%7g, ncp=%7g) ==> x= %10g:", t, df, ncp, x); + if (x <= 0.) { + return finish(0., del, negdel, lowerTail, logP); + } + + /* LDOUBLE */double tnc; + /* else x > 0. <==> t != 0 */ + double lambda = del * del; + /* LDOUBLE */double p = .5 * Math.exp(-.5 * lambda); + debugPrintf("\t p=%10Lg\n", p); + + if (p == 0.) { /* underflow! */ + /// GnuR note: really use an other algorithm for this case + RMathError.error(MLError.UNDERFLOW, "pnt"); + RMathError.error(MLError.RANGE, "pnt"); /* |ncp| too large */ + return DPQ.rdt0(lowerTail, logP); + } + + debugPrintf("it 1e5*(godd, geven)| p q s pnt(*) errbd\n"); + + /* LDOUBLE */double q = M_SQRT_2dPI * p * del; + s = .5 - p; + /* s = 0.5 - p = 0.5*(1 - Math.exp(-.5 L)) = -0.5*expm1(-.5 L)) */ + if (s < 1e-7) { + s = -0.5 * RMath.expm1(-0.5 * lambda); + } + double a = .5; + double b = .5 * df; + /* + * rxb = (1 - x) ^ b [ ~= 1 - b*x for tiny x --> see 'xeven' below] where '(1 - x)' =: rxb + * {accurately!} above + */ + rxb = Math.pow(rxb, b); + double albeta = M_LN_SQRT_PI + lgammafn(b) - lgammafn(.5 + b); + /* LDOUBLE */double xodd = pbeta.evaluate(x, a, b, /* lower */true, /* logP */false); + /* LDOUBLE */double godd = 2. * rxb * Math.exp(a * Math.log(x) - albeta); + tnc = b * x; + /* LDOUBLE */double xeven = (tnc < DBL_EPSILON) ? tnc : 1. - rxb; + /* LDOUBLE */double geven = tnc * rxb; + tnc = p * xodd + q * xeven; + + /* repeat until convergence or iteration limit */ + for (int it = 1; it <= itrmax; it++) { + a += 1.; + xodd -= godd; + xeven -= geven; + godd *= x * (a + b - 1.) / a; + geven *= x * (a + b - .5) / (a + .5); + p *= lambda / (2 * it); + q *= lambda / (2 * it + 1); + tnc += p * xodd + q * xeven; + s -= p; + /* R 2.4.0 added test for rounding error here. */ + if (s < -1.e-10) { /* happens e.g. for (t,df,ncp)=(40,10,38.5), after 799 it. */ + RMathError.error(MLError.PRECISION, "pnt"); + debugPrintf("s = %#14.7Lg < 0 !!! ---> non-convergence!!\n", s); + return finish(tnc, del, negdel, lowerTail, logP); + } + if (s <= 0 && it > 1) { + return finish(tnc, del, negdel, lowerTail, logP); + } + double errbd = 2. * s * (xodd - godd); + debugPrintf("%3d %.4g %.4g|%.4Lg %.4g %.4g %.10g %.4g\n", + it, 1e5 * godd, 1e5 * geven, p, q, s, tnc, errbd); + if (TOMS708.fabs(errbd) < errmax) { + return finish(tnc, del, negdel, lowerTail, logP); /* convergence */ + } + } + /* non-convergence: */ + RMathError.error(MLError.NOCONV, "pnt"); + return finish(tnc, del, negdel, lowerTail, logP); + } + + private double finish(double tncIn, double del, boolean negdel, boolean lowerTailIn, boolean logP) { + /* LDOUBLE */double tnc = tncIn + pnorm.evaluate(-del, 0., 1., /* lower */true, /* logP */false); + + boolean lowerTail = lowerTailIn != negdel; /* xor */ + if (tnc > 1 - 1e-10 && lowerTail) { + RMathError.error(MLError.PRECISION, "pnt{final}"); + } + return DPQ.rdtval(RMath.fmin2(tnc, 1.) /* Precaution */, lowerTail, logP); + } + + @SuppressWarnings("unused") + private void debugPrintf(String fmt, Object... args) { + // System.out.printf(fmt + "\n", args); + } +} diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/Qnt.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/Qnt.java new file mode 100644 index 0000000000000000000000000000000000000000..2479dff17891dd68b71ce5f42d7022afea95048e --- /dev/null +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/Qnt.java @@ -0,0 +1,87 @@ +/* + * This material is distributed under the GNU General Public License + * Version 2. You may review the terms of this license at + * http://www.gnu.org/licenses/gpl-2.0.html + * + * Copyright (c) 2006-2015, The R Core Team + * Copyright (c) 2017, Oracle and/or its affiliates + * + * All rights reserved. + */ +package com.oracle.truffle.r.runtime.nmath.distr; + +import static com.oracle.truffle.r.runtime.nmath.MathConstants.DBL_EPSILON; +import static com.oracle.truffle.r.runtime.nmath.MathConstants.DBL_MAX; +import static com.oracle.truffle.r.runtime.nmath.distr.Qnorm.qnorm; + +import com.oracle.truffle.r.runtime.nmath.DPQ; +import com.oracle.truffle.r.runtime.nmath.DPQ.EarlyReturn; +import com.oracle.truffle.r.runtime.nmath.MathFunctions.Function3_2; +import com.oracle.truffle.r.runtime.nmath.RMath; +import com.oracle.truffle.r.runtime.nmath.RMathError; +import com.oracle.truffle.r.runtime.nmath.TOMS708; + +public final class Qnt implements Function3_2 { + private static final double accu = 1e-13; + private static final double Eps = 1e-11; /* must be > accu */ + + private final Pnt pnt = new Pnt(); + private final Qt qt = new Qt(); + + @Override + public double evaluate(double pIn, double df, double ncp, boolean lowerTail, boolean logP) { + if (Double.isNaN(pIn) || Double.isNaN(df) || Double.isNaN(ncp)) { + return pIn + df + ncp; + } + if (df <= 0.0) { + return RMathError.defaultError(); + } + + if (ncp == 0.0 && df >= 1.0) { + return qt.evaluate(pIn, df, lowerTail, logP); + } + + try { + DPQ.rqp01boundaries(pIn, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, lowerTail, logP); + } catch (EarlyReturn e) { + return e.result; + } + + if (!Double.isFinite(df)) { + // df = Inf ==> limit N(ncp,1) + return qnorm(pIn, ncp, 1., lowerTail, logP); + } + + double p = DPQ.rdtqiv(pIn, lowerTail, logP); + + /* + * Invert pnt(.) : 1. finding an upper and lower bound + */ + if (p > 1 - DBL_EPSILON) { + return Double.POSITIVE_INFINITY; + } + double pp = RMath.fmin2(1 - DBL_EPSILON, p * (1 + Eps)); + double ux = RMath.fmax2(1., ncp); + while (ux < DBL_MAX && pnt.evaluate(ux, df, ncp, true, false) < pp) { + ux *= 2; + } + pp = p * (1 - Eps); + double lx = RMath.fmin2(-1., -ncp); + while (lx > -DBL_MAX && pnt.evaluate(lx, df, ncp, true, false) > pp) { + lx *= 2; + } + + /* 2. interval (lx,ux) halving : */ + double nx; + do { + nx = 0.5 * (lx + ux); // could be zero + if (pnt.evaluate(nx, df, ncp, true, false) > p) { + ux = nx; + } else { + lx = nx; + } + } while ((ux - lx) > accu * RMath.fmax2(TOMS708.fabs(lx), TOMS708.fabs(ux))); + + return 0.5 * (lx + ux); + } +} diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test index aec62f93a850d43f8e9755b8603f5e3c162a250a..1b894cb4b72e5e69055bc3375ee2cc9f5e233965 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test @@ -112726,6 +112726,62 @@ Error in dsignrank(0, Inf) : [8] -6.931472 -Inf -Inf -Inf -6.931472 -6.931472 -6.931472 [15] -Inf NaN +##com.oracle.truffle.r.test.library.stats.TestDistributions.testDensityFunctions#Output.MayIgnoreWarningContext# +#dt(0, -Inf, ncp=0.5) +[1] NaN +Warning message: +In dt(0, -Inf, ncp = 0.5) : NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testDensityFunctions#Output.MayIgnoreWarningContext# +#dt(0, 3e100, -Inf) +[1] 0 + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testDensityFunctions#Output.MayIgnoreWarningContext# +#dt(0, 3e100, NaN) +[1] NaN + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testDensityFunctions#Output.MayIgnoreWarningContext# +#dt(0, NaN, ncp=0.5) +[1] NaN + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testDensityFunctions#Output.MayIgnoreWarningContext# +#dt(c(-10, -5, -4, -3, -2, -1, 0, 1.1, 2, 3, 4, 10, 100), Inf, ncp=-1, log=F) + [1] 1.027977e-18 1.338302e-04 4.431848e-03 5.399097e-02 2.419707e-01 + [6] 3.989423e-01 2.419707e-01 4.398360e-02 4.431848e-03 1.338302e-04 +[11] 1.486720e-06 2.118819e-27 0.000000e+00 + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testDensityFunctions#Output.MayIgnoreWarningContext# +#dt(c(-10, -5, -4, -3, -2, -1, 0, 1.1, 2, 3, 4, 10, 100), Inf, ncp=-1, log=T) + [1] -41.4189385 -8.9189385 -5.4189385 -2.9189385 -1.4189385 + [6] -0.9189385 -1.4189385 -3.1239385 -5.4189385 -8.9189385 +[11] -13.4189385 -61.4189385 -5101.4189385 + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testDensityFunctions#Output.MayIgnoreWarningContext# +#dt(c(-30, -20, -4, 0.5, 1.3, 2, 3, 4, 10, 100, -Inf, -0.42e-30, 0, 0.42e-30, Inf, NaN), 3e100, ncp=0.5, log=F) + [1] 3.978223e-203 2.211984e-92 1.598374e-05 3.989423e-01 2.896916e-01 + [6] 1.295176e-01 1.752830e-02 8.726827e-04 1.007794e-20 0.000000e+00 +[11] 0.000000e+00 3.520653e-01 3.520653e-01 3.520653e-01 0.000000e+00 +[16] NaN + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testDensityFunctions#Output.MayIgnoreWarningContext# +#dt(c(-30, -20, -4, 0.5, 1.3, 2, 3, 4, 10, 100, -Inf, -0.42e-30, 0, 0.42e-30, Inf, NaN), 3e100, ncp=0.5, log=T) + [1] -466.0439385 -211.0439385 -11.0439385 -0.9189385 -1.2389385 + [6] -2.0439385 -4.0439385 -7.0439385 -46.0439385 -4951.0439385 +[11] -Inf -1.0439385 -1.0439385 -1.0439385 -Inf +[16] NaN + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testDensityFunctions#Output.MayIgnoreWarningContext# +#dt(c(1), -10, ncp=2, log=F) +[1] NaN +Warning message: +In dt(c(1), -10, ncp = 2, log = F) : NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testDensityFunctions#Output.MayIgnoreWarningContext# +#dt(c(1), -10, ncp=2, log=T) +[1] NaN +Warning message: +In dt(c(1), -10, ncp = 2, log = T) : NaNs produced + ##com.oracle.truffle.r.test.library.stats.TestDistributions.testDensityFunctions#Output.MayIgnoreWarningContext# #dunif(0, -3, -Inf) [1] NaN @@ -114474,6 +114530,100 @@ In psignrank(0, Inf) : NaNs produced [11] -Inf -6.9314718056 -6.9314718056 -6.9314718056 0.0000000000 [16] NaN +##com.oracle.truffle.r.test.library.stats.TestDistributions.testDistributionFunctions#Output.MayIgnoreWarningContext# +#pt(0, -Inf, ncp=0.5) +[1] NaN +Warning message: +In pt(0, -Inf, ncp = 0.5) : NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testDistributionFunctions#Output.MayIgnoreWarningContext# +#pt(0, 3e100, -Inf) +[1] 1 + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testDistributionFunctions#Output.MayIgnoreWarningContext# +#pt(0, 3e100, NaN) +[1] NaN + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testDistributionFunctions#Output.MayIgnoreWarningContext# +#pt(0, NaN, ncp=0.5) +[1] NaN + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testDistributionFunctions#Output.MayIgnoreWarningContext# +#pt(c(-10, -5, -4, -3, -2, -1, 0, 1.1, 2, 3, 4, 10, 100), Inf, ncp=-1, lower.tail=F, log.p=F) + [1] 1.000000e+00 9.999683e-01 9.986501e-01 9.772499e-01 8.413447e-01 + [6] 5.000000e-01 1.586553e-01 1.786442e-02 1.349898e-03 3.167124e-05 +[11] 2.866516e-07 1.910660e-28 0.000000e+00 + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testDistributionFunctions#Output.MayIgnoreWarningContext# +#pt(c(-10, -5, -4, -3, -2, -1, 0, 1.1, 2, 3, 4, 10, 100), Inf, ncp=-1, lower.tail=F, log.p=T) + [1] -1.128588e-19 -3.167174e-05 -1.350810e-03 -2.301291e-02 -1.727538e-01 + [6] -6.931472e-01 -1.841022e+00 -4.024944e+00 -6.607726e+00 -1.036010e+01 +[11] -1.506500e+01 -6.382493e+01 -5.106034e+03 + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testDistributionFunctions#Output.MayIgnoreWarningContext# +#pt(c(-10, -5, -4, -3, -2, -1, 0, 1.1, 2, 3, 4, 10, 100), Inf, ncp=-1, lower.tail=T, log.p=F) + [1] 1.128588e-19 3.167124e-05 1.349898e-03 2.275013e-02 1.586553e-01 + [6] 5.000000e-01 8.413447e-01 9.821356e-01 9.986501e-01 9.999683e-01 +[11] 9.999997e-01 1.000000e+00 1.000000e+00 + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testDistributionFunctions#Output.MayIgnoreWarningContext# +#pt(c(-10, -5, -4, -3, -2, -1, 0, 1.1, 2, 3, 4, 10, 100), Inf, ncp=-1, lower.tail=T, log.p=T) + [1] -4.362815e+01 -1.036010e+01 -6.607726e+00 -3.783184e+00 -1.841022e+00 + [6] -6.931472e-01 -1.727538e-01 -1.802592e-02 -1.350810e-03 -3.167174e-05 +[11] -2.866516e-07 -1.910660e-28 0.000000e+00 + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testDistributionFunctions#Output.MayIgnoreWarningContext# +#pt(c(-30, -20, -4, 0.5, 1.3, 2, 3, 4, 10, 100, -Inf, -0.42e-30, 0, 0.42e-30, Inf, NaN), 3e100, ncp=0.5, lower.tail=F, log.p=F) + [1] 1.000000e+00 1.000000e+00 9.999966e-01 5.000000e-01 2.118554e-01 + [6] 6.680720e-02 6.209665e-03 2.326291e-04 1.049452e-21 0.000000e+00 +[11] 1.000000e+00 6.914625e-01 6.914625e-01 6.914625e-01 0.000000e+00 +[16] NaN + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testDistributionFunctions#Output.MayIgnoreWarningContext# +#pt(c(-30, -20, -4, 0.5, 1.3, 2, 3, 4, 10, 100, -Inf, -0.42e-30, 0, 0.42e-30, Inf, NaN), 3e100, ncp=0.5, lower.tail=F, log.p=T) + [1] -1.302938e-204 -1.076467e-93 -3.397679e-06 -6.931472e-01 -1.551851e+00 + [6] -2.705944e+00 -5.081648e+00 -8.366065e+00 -4.830602e+01 -4.955644e+03 +[11] 0.000000e+00 -3.689464e-01 -3.689464e-01 -3.689464e-01 -Inf +[16] NaN + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testDistributionFunctions#Output.MayIgnoreWarningContext# +#pt(c(-30, -20, -4, 0.5, 1.3, 2, 3, 4, 10, 100, -Inf, -0.42e-30, 0, 0.42e-30, Inf, NaN), 3e100, ncp=0.5, lower.tail=T, log.p=F) + [1] 1.302938e-204 1.076467e-93 3.397673e-06 5.000000e-01 7.881446e-01 + [6] 9.331928e-01 9.937903e-01 9.997674e-01 1.000000e+00 1.000000e+00 +[11] 0.000000e+00 3.085375e-01 3.085375e-01 3.085375e-01 1.000000e+00 +[16] NaN + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testDistributionFunctions#Output.MayIgnoreWarningContext# +#pt(c(-30, -20, -4, 0.5, 1.3, 2, 3, 4, 10, 100, -Inf, -0.42e-30, 0, 0.42e-30, Inf, NaN), 3e100, ncp=0.5, lower.tail=T, log.p=T) + [1] -4.694627e+02 -2.140667e+02 -1.259242e+01 -6.931472e-01 -2.380737e-01 + [6] -6.914346e-02 -6.229025e-03 -2.326561e-04 -1.049452e-21 0.000000e+00 +[11] -Inf -1.175912e+00 -1.175912e+00 -1.175912e+00 0.000000e+00 +[16] NaN + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testDistributionFunctions#Output.MayIgnoreWarningContext# +#pt(c(1), -10, ncp=2, lower.tail=F, log.p=F) +[1] NaN +Warning message: +In pt(c(1), -10, ncp = 2, lower.tail = F, log.p = F) : NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testDistributionFunctions#Output.MayIgnoreWarningContext# +#pt(c(1), -10, ncp=2, lower.tail=F, log.p=T) +[1] NaN +Warning message: +In pt(c(1), -10, ncp = 2, lower.tail = F, log.p = T) : NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testDistributionFunctions#Output.MayIgnoreWarningContext# +#pt(c(1), -10, ncp=2, lower.tail=T, log.p=F) +[1] NaN +Warning message: +In pt(c(1), -10, ncp = 2, lower.tail = T, log.p = F) : NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testDistributionFunctions#Output.MayIgnoreWarningContext# +#pt(c(1), -10, ncp=2, lower.tail=T, log.p=T) +[1] NaN +Warning message: +In pt(c(1), -10, ncp = 2, lower.tail = T, log.p = T) : NaNs produced + ##com.oracle.truffle.r.test.library.stats.TestDistributions.testDistributionFunctions#Output.MayIgnoreWarningContext# #punif(0, -3, -Inf) [1] NaN @@ -116689,6 +116839,118 @@ Warning message: In qsignrank(log(c(0, 4.2e-79, 0.1, 0.5, 0.7, 1 - 4.2e-79, 1)), : NaNs produced +##com.oracle.truffle.r.test.library.stats.TestDistributions.testQuantileFunctions#Output.MayIgnoreWarningContext# +#qt(-0.42e-38, 3e100, ncp=0.5) +[1] NaN +Warning message: +In qt(-4.2e-39, 3e+100, ncp = 0.5) : NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testQuantileFunctions#Output.MayIgnoreWarningContext# +#qt(-42, 3e100, ncp=0.5) +[1] NaN +Warning message: +In qt(-42, 3e+100, ncp = 0.5) : NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testQuantileFunctions#Output.MayIgnoreWarningContext# +#qt(-Inf, 3e100, ncp=0.5) +[1] NaN +Warning message: +In qt(-Inf, 3e+100, ncp = 0.5) : NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testQuantileFunctions#Output.MayIgnoreWarningContext# +#qt(0, -Inf, ncp=0.5) +[1] NaN +Warning message: +In qt(0, -Inf, ncp = 0.5) : NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testQuantileFunctions#Output.MayIgnoreWarningContext# +#qt(0, 3e100, -Inf) +[1] -Inf + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testQuantileFunctions#Output.MayIgnoreWarningContext# +#qt(0, 3e100, NaN) +[1] NaN + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testQuantileFunctions#Output.MayIgnoreWarningContext# +#qt(0, NaN, ncp=0.5) +[1] NaN + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testQuantileFunctions#Output.MayIgnoreWarningContext# +#qt(Inf, 3e100, ncp=0.5) +[1] NaN +Warning message: +In qt(Inf, 3e+100, ncp = 0.5) : NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testQuantileFunctions#Output.MayIgnoreWarningContext# +#qt(NaN, 3e100, ncp=0.5) +[1] NaN + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testQuantileFunctions#Output.MayIgnoreWarningContext# +#qt(c(0, 42e-80, 0.1, 0.5, 0.7, 1-42e-80, 1), -10, ncp=2, lower.tail=F, log.p=F) +[1] NaN NaN NaN NaN NaN NaN NaN +Warning message: +In qt(c(0, 4.2e-79, 0.1, 0.5, 0.7, 1 - 4.2e-79, 1), -10, ncp = 2, : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testQuantileFunctions#Output.MayIgnoreWarningContext# +#qt(c(0, 42e-80, 0.1, 0.5, 0.7, 1-42e-80, 1), -10, ncp=2, lower.tail=T, log.p=F) +[1] NaN NaN NaN NaN NaN NaN NaN +Warning message: +In qt(c(0, 4.2e-79, 0.1, 0.5, 0.7, 1 - 4.2e-79, 1), -10, ncp = 2, : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testQuantileFunctions#Output.MayIgnoreWarningContext# +#qt(c(0, 42e-80, 0.1, 0.5, 0.7, 1-42e-80, 1), 3e100, ncp=0.5, lower.tail=F, log.p=F) +[1] Inf Inf 1.78155157 0.50000000 -0.02440051 -Inf +[7] -Inf + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testQuantileFunctions#Output.MayIgnoreWarningContext# +#qt(c(0, 42e-80, 0.1, 0.5, 0.7, 1-42e-80, 1), 3e100, ncp=0.5, lower.tail=T, log.p=F) +[1] -Inf -18.2943519 -0.7815516 0.5000000 1.0244005 Inf +[7] Inf + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testQuantileFunctions#Output.MayIgnoreWarningContext# +#qt(c(0, 42e-80, 0.1, 0.5, 0.7, 1-42e-80, 1), Inf, ncp=-1, lower.tail=F, log.p=F) +[1] Inf 17.7943519 0.2815516 -1.0000000 -1.5244005 -Inf -Inf + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testQuantileFunctions#Output.MayIgnoreWarningContext# +#qt(c(0, 42e-80, 0.1, 0.5, 0.7, 1-42e-80, 1), Inf, ncp=-1, lower.tail=T, log.p=F) +[1] -Inf -19.7943519 -2.2815516 -1.0000000 -0.4755995 Inf +[7] Inf + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testQuantileFunctions#Output.MayIgnoreWarningContext# +#qt(log(c(0, 42e-80, 0.1, 0.5, 0.7, 1-42e-80, 1)), -10, ncp=2, lower.tail=F, log.p=T) +[1] NaN NaN NaN NaN NaN NaN NaN +Warning message: +In qt(log(c(0, 4.2e-79, 0.1, 0.5, 0.7, 1 - 4.2e-79, 1)), -10, ncp = 2, : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testQuantileFunctions#Output.MayIgnoreWarningContext# +#qt(log(c(0, 42e-80, 0.1, 0.5, 0.7, 1-42e-80, 1)), -10, ncp=2, lower.tail=T, log.p=T) +[1] NaN NaN NaN NaN NaN NaN NaN +Warning message: +In qt(log(c(0, 4.2e-79, 0.1, 0.5, 0.7, 1 - 4.2e-79, 1)), -10, ncp = 2, : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testQuantileFunctions#Output.MayIgnoreWarningContext# +#qt(log(c(0, 42e-80, 0.1, 0.5, 0.7, 1-42e-80, 1)), 3e100, ncp=0.5, lower.tail=F, log.p=T) +[1] Inf Inf 1.78155157 0.50000000 -0.02440051 -Inf +[7] -Inf + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testQuantileFunctions#Output.MayIgnoreWarningContext# +#qt(log(c(0, 42e-80, 0.1, 0.5, 0.7, 1-42e-80, 1)), 3e100, ncp=0.5, lower.tail=T, log.p=T) +[1] -Inf -18.2943519 -0.7815516 0.5000000 1.0244005 Inf +[7] Inf + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testQuantileFunctions#Output.MayIgnoreWarningContext# +#qt(log(c(0, 42e-80, 0.1, 0.5, 0.7, 1-42e-80, 1)), Inf, ncp=-1, lower.tail=F, log.p=T) +[1] Inf 17.7943519 0.2815516 -1.0000000 -1.5244005 -Inf -Inf + +##com.oracle.truffle.r.test.library.stats.TestDistributions.testQuantileFunctions#Output.MayIgnoreWarningContext# +#qt(log(c(0, 42e-80, 0.1, 0.5, 0.7, 1-42e-80, 1)), Inf, ncp=-1, lower.tail=T, log.p=T) +[1] -Inf -19.7943519 -2.2815516 -1.0000000 -0.4755995 Inf +[7] Inf + ##com.oracle.truffle.r.test.library.stats.TestDistributions.testQuantileFunctions#Output.MayIgnoreWarningContext# #qunif(-0.42e-38, -3, 3.3) [1] NaN diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/stats/TestDistributions.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/stats/TestDistributions.java index 113814e3b9cde8bf72c1725c9af878b64dc19bb1..c142d36cf8f44d9530ec82bb534dae93212fcad5 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/stats/TestDistributions.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/stats/TestDistributions.java @@ -44,6 +44,7 @@ public class TestDistributions extends TestBase { private static final String[] DEFAULT_Q = new String[]{"-Inf", "-0.42e-30", "0", "0.42e-30", "Inf", "NaN"}; private static final String PROBABILITIES = "c(0, 42e-80, 0.1, 0.5, 0.7, 1-42e-80, 1)"; private static final String[] ERROR_PROBABILITIES = new String[]{"Inf", "-Inf", "NaN", "-42", "-0.42e-38"}; + private static final String[] DEFAULT_ERROR_PARAMS = {"-Inf", "Inf", "NaN"}; // @formatter:off /** @@ -151,7 +152,15 @@ public class TestDistributions extends TestBase { distr("signrank"). addErrorParamValues("-3", "0"). test("10", withDefaultQ("5", "15", "20", "27", "35", "50", "54", "55", "56", "100")). - test("5.5", withQuantiles("0.3", "0.6", "2", "3", "6", "15", "20")) + test("5.5", withQuantiles("0.3", "0.6", "2", "3", "6", "15", "20")), + // Non-central t distribution (t distr. with extra parameter ncp) + distr("t"). + clearDefaultErrorParamValues(). + addErrorParamValues("-Inf", "NaN"). + test("3e100, ncp=0.5", withDefaultQ("-30", "-20", "-4", "0.5", "1.3", "2", "3", "4", "10", "100")). + test("Inf, ncp=-1", withQuantiles("-10", "-5", "-4", "-3", "-2", "-1", "0", "1.1", "2", "3", "4", "10", "100")). + // negative first parameter => error + test("-10, ncp=2", withQuantiles("1")) }; // @formatter:on @@ -249,7 +258,7 @@ public class TestDistributions extends TestBase { DistrTest(String name) { this.name = name; - addErrorParamValues("-Inf", "Inf", "NaN"); + addErrorParamValues(DEFAULT_ERROR_PARAMS); } public DistrTest test(String params, String[] quantiles) { @@ -269,7 +278,6 @@ public class TestDistributions extends TestBase { * but this method is here to make the API "complete". May be removed if all distributions * already have tests and non of them needs it. */ - @SuppressWarnings("unused") public DistrTest clearDefaultErrorParamValues() { errorParamValues.clear(); return this; diff --git a/mx.fastr/copyrights/gnu_r.foundation.copyright.star b/mx.fastr/copyrights/gnu_r.foundation.copyright.star new file mode 100644 index 0000000000000000000000000000000000000000..fd68e5453f6ecded2f090283cb5f60befa8f6c49 --- /dev/null +++ b/mx.fastr/copyrights/gnu_r.foundation.copyright.star @@ -0,0 +1,10 @@ +/* + * This material is distributed under the GNU General Public License + * Version 2. You may review the terms of this license at + * http://www.gnu.org/licenses/gpl-2.0.html + * + * Copyright (c) 1995-2015, The R Foundation + * Copyright (c) 2017, Oracle and/or its affiliates + * + * All rights reserved. + */ diff --git a/mx.fastr/copyrights/gnu_r.foundation.copyright.star.regex b/mx.fastr/copyrights/gnu_r.foundation.copyright.star.regex new file mode 100644 index 0000000000000000000000000000000000000000..b2688a9d63cece9df9bf726daeb2253e67bc7c12 --- /dev/null +++ b/mx.fastr/copyrights/gnu_r.foundation.copyright.star.regex @@ -0,0 +1 @@ +/\*\n \* This material is distributed under the GNU General Public License\n \* Version 2. You may review the terms of this license at\n \* http://www.gnu.org/licenses/gpl-2.0.html\n \*\n \* Copyright \(c\) (?:[1-2][09][0-9][0-9]--?)?(:?[1-2][09])?[0-9]?[0-9], The R Foundation\n \* Copyright \(c\) (?:(20[0-9][0-9]), )?(20[0-9][0-9]), Oracle and/or its affiliates\n \*\n \* All rights reserved.\n \*/\n.* diff --git a/mx.fastr/copyrights/overrides b/mx.fastr/copyrights/overrides index df3d2df47da92d0af1a38d77f0a8e635573b2460..5b8f4bcc37df2602f255180d9c733774a369f2c1 100644 --- a/mx.fastr/copyrights/overrides +++ b/mx.fastr/copyrights/overrides @@ -59,6 +59,9 @@ com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/PNBeta com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/QNBeta.java,gnu_r.core.copyright com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/Qnf.java,gnu_r.core.copyright com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/Dnf.java,gnu_r.core.copyright +com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/Qnt.java,gnu_r.core.copyright +com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/Pnt.java,gnu_r.core.copyright +com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/Dnt.java,gnu_r.foundation.copyright com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/DNBeta.java,gnu_r_ihaka_core.copyright com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/LBeta.java,gnu_r_ihaka.copyright com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/Pbinom.java,gnu_r_ihaka.copyright