Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 30DF2EE80 for ; Tue, 15 Jan 2013 12:16:17 +0000 (UTC) Received: (qmail 52053 invoked by uid 500); 15 Jan 2013 12:16:16 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 51618 invoked by uid 500); 15 Jan 2013 12:16:13 -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 51572 invoked by uid 99); 15 Jan 2013 12:16:11 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 15 Jan 2013 12:16:11 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 15 Jan 2013 12:16:09 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id AF2CE23888D2; Tue, 15 Jan 2013 12:15:50 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1433367 - in /commons/proper/math/trunk/src: changes/changes.xml main/java/org/apache/commons/math3/distribution/MultivariateNormalDistribution.java test/java/org/apache/commons/math3/distribution/MultivariateNormalDistributionTest.java Date: Tue, 15 Jan 2013 12:15:50 -0000 To: commits@commons.apache.org From: erans@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130115121550.AF2CE23888D2@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: erans Date: Tue Jan 15 12:15:50 2013 New Revision: 1433367 URL: http://svn.apache.org/viewvc?rev=1433367&view=rev Log: MATH-929 Fixed truncated value. Thanks to Piotr Wydrych. Added unit test: comparing density values with univariate normal distribution. Modified: commons/proper/math/trunk/src/changes/changes.xml commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/MultivariateNormalDistribution.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/MultivariateNormalDistributionTest.java Modified: commons/proper/math/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/changes/changes.xml?rev=1433367&r1=1433366&r2=1433367&view=diff ============================================================================== --- commons/proper/math/trunk/src/changes/changes.xml (original) +++ commons/proper/math/trunk/src/changes/changes.xml Tue Jan 15 12:15:50 2013 @@ -55,6 +55,9 @@ This is a minor release: It combines bug Changes to existing features were made in a backwards-compatible way such as to allow drop-in replacement of the v3.1[.1] JAR file. "> + + Fixed truncated value in "MultivariateNormalDistribution". + Made "BitStreamGenerator" implement the "Serializable" interface. Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/MultivariateNormalDistribution.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/MultivariateNormalDistribution.java?rev=1433367&r1=1433366&r2=1433367&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/MultivariateNormalDistribution.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/MultivariateNormalDistribution.java Tue Jan 15 12:15:50 2013 @@ -180,7 +180,7 @@ public class MultivariateNormalDistribut throw new DimensionMismatchException(vals.length, dim); } - return FastMath.pow(2 * FastMath.PI, -dim / 2) * + return FastMath.pow(2 * FastMath.PI, -0.5 * dim) * FastMath.pow(covarianceMatrixDeterminant, -0.5) * getExponentTerm(vals); } Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/MultivariateNormalDistributionTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/MultivariateNormalDistributionTest.java?rev=1433367&r1=1433366&r2=1433367&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/MultivariateNormalDistributionTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/MultivariateNormalDistributionTest.java Tue Jan 15 12:15:50 2013 @@ -20,6 +20,7 @@ package org.apache.commons.math3.distrib import org.apache.commons.math3.stat.correlation.Covariance; import org.apache.commons.math3.linear.RealMatrix; +import java.util.Random; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -130,4 +131,24 @@ public class MultivariateNormalDistribut Assert.assertEquals(correctDensities[i], densities[i], 1e-16); } } + + /** + * Test the accuracy of the distribution when calculating densities. + */ + @Test + public void testUnivariateDistribution() { + final double[] mu = { -1.5 }; + final double[][] sigma = { { 1 } }; + + final MultivariateNormalDistribution multi = new MultivariateNormalDistribution(mu, sigma); + + final NormalDistribution uni = new NormalDistribution(mu[0], sigma[0][0]); + final Random rng = new Random(); + final int numCases = 100; + final double tol = Math.ulp(1d); + for (int i = 0; i < numCases; i++) { + final double v = rng.nextDouble() * 10 - 5; + Assert.assertEquals(uni.density(v), multi.density(new double[] { v }), tol); + } + } }