From commits-return-61113-archive-asf-public=cust-asf.ponee.io@commons.apache.org Sat Jan 27 14:56:51 2018 Return-Path: X-Original-To: archive-asf-public@eu.ponee.io Delivered-To: archive-asf-public@eu.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by mx-eu-01.ponee.io (Postfix) with ESMTP id E4BE418065B for ; Sat, 27 Jan 2018 14:56:51 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id D4E8F160C2F; Sat, 27 Jan 2018 13:56:51 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 28739160C30 for ; Sat, 27 Jan 2018 14:56:51 +0100 (CET) Received: (qmail 12529 invoked by uid 500); 27 Jan 2018 13:56:50 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 12517 invoked by uid 99); 27 Jan 2018 13:56:50 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 27 Jan 2018 13:56:50 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 8E862DFAB9; Sat, 27 Jan 2018 13:56:47 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: erans@apache.org To: commits@commons.apache.org Date: Sat, 27 Jan 2018 13:56:48 -0000 Message-Id: In-Reply-To: <0c454720d1f447f69aac4c1f35d46dd9@git.apache.org> References: <0c454720d1f447f69aac4c1f35d46dd9@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/2] commons-statistics git commit: Cache value of mean and variance. Cache value of mean and variance. Project: http://git-wip-us.apache.org/repos/asf/commons-statistics/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-statistics/commit/9cadb96c Tree: http://git-wip-us.apache.org/repos/asf/commons-statistics/tree/9cadb96c Diff: http://git-wip-us.apache.org/repos/asf/commons-statistics/diff/9cadb96c Branch: refs/heads/master Commit: 9cadb96cbb82c37187b6b4833c73cc0340c08454 Parents: 33d1552 Author: Gilles Sadowski Authored: Sat Jan 27 14:55:07 2018 +0100 Committer: Gilles Sadowski Committed: Sat Jan 27 14:55:07 2018 +0100 ---------------------------------------------------------------------- .../statistics/distribution/TDistribution.java | 43 ++++++++------------ 1 file changed, 18 insertions(+), 25 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-statistics/blob/9cadb96c/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/TDistribution.java ---------------------------------------------------------------------- diff --git a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/TDistribution.java b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/TDistribution.java index 7177308..a579e15 100644 --- a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/TDistribution.java +++ b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/TDistribution.java @@ -29,6 +29,10 @@ public class TDistribution extends AbstractContinuousDistribution { private final double dofOver2; /** Cached value. */ private final double factor; + /** Cached value. */ + private final double mean; + /** Cached value. */ + private final double variance; /** * Creates a distribution. @@ -47,6 +51,11 @@ public class TDistribution extends AbstractContinuousDistribution { factor = LogGamma.value(dofOver2 + 0.5) - 0.5 * (Math.log(Math.PI) + Math.log(degreesOfFreedom)) - LogGamma.value(dofOver2); + mean = degreesOfFreedom > 1 ? 0 : + Double.NaN; + variance = degreesOfFreedom > 2 ? degreesOfFreedom / (degreesOfFreedom - 2) : + degreesOfFreedom > 1 && degreesOfFreedom <= 2 ? Double.POSITIVE_INFINITY : + Double.NaN; } /** @@ -97,17 +106,13 @@ public class TDistribution extends AbstractContinuousDistribution { * * For degrees of freedom parameter {@code df}, the mean is *
    - *
  • if {@code df > 1} then {@code 0},
  • - *
  • else undefined ({@code Double.NaN}).
  • + *
  • zero if {@code df > 1}, and
  • + *
  • undefined ({@code Double.NaN}) otherwise.
  • *
*/ @Override public double getMean() { - if (degreesOfFreedom > 1) { - return 0; - } - - return Double.NaN; + return mean; } /** @@ -115,31 +120,20 @@ public class TDistribution extends AbstractContinuousDistribution { * * For degrees of freedom parameter {@code df}, the variance is *
    - *
  • if {@code df > 2} then {@code df / (df - 2)},
  • - *
  • if {@code 1 < df <= 2} then positive infinity - * ({@code Double.POSITIVE_INFINITY}),
  • - *
  • else undefined ({@code Double.NaN}).
  • + *
  • {@code df / (df - 2)} if {@code df > 2},
  • + *
  • infinite ({@code Double.POSITIVE_INFINITY}) if {@code 1 < df <= 2}, and
  • + *
  • undefined ({@code Double.NaN}) otherwise.
  • *
*/ @Override public double getVariance() { - if (degreesOfFreedom > 2) { - return degreesOfFreedom / (degreesOfFreedom - 2); - } - - if (degreesOfFreedom > 1 && - degreesOfFreedom <= 2) { - return Double.POSITIVE_INFINITY; - } - - return Double.NaN; + return variance; } /** * {@inheritDoc} * - * The lower bound of the support is always negative infinity no matter the - * parameters. + * The lower bound of the support is always negative infinity.. * * @return lower bound of the support (always * {@code Double.NEGATIVE_INFINITY}) @@ -152,8 +146,7 @@ public class TDistribution extends AbstractContinuousDistribution { /** * {@inheritDoc} * - * The upper bound of the support is always positive infinity no matter the - * parameters. + * The upper bound of the support is always positive infinity. * * @return upper bound of the support (always * {@code Double.POSITIVE_INFINITY})