MATH-929
Fixed truncated value. Thanks to Piotr Wydrych. Added unit test: comparing density values with univariate normal distribution. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1433367 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fea4dd914b
commit
cedf0d27f9
|
@ -55,6 +55,9 @@ This is a minor release: It combines bug fixes and new features.
|
||||||
Changes to existing features were made in a backwards-compatible
|
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.
|
way such as to allow drop-in replacement of the v3.1[.1] JAR file.
|
||||||
">
|
">
|
||||||
|
<action dev="erans" type="fix" issue="MATH-929" due-to="Piotr Wydrych">
|
||||||
|
Fixed truncated value in "MultivariateNormalDistribution".
|
||||||
|
</action>
|
||||||
<action dev="erans" type="fix" issue="MATH-927" due-to="Dennis Hendriks">
|
<action dev="erans" type="fix" issue="MATH-927" due-to="Dennis Hendriks">
|
||||||
Made "BitStreamGenerator" implement the "Serializable" interface.
|
Made "BitStreamGenerator" implement the "Serializable" interface.
|
||||||
</action>
|
</action>
|
||||||
|
|
|
@ -180,7 +180,7 @@ public class MultivariateNormalDistribution
|
||||||
throw new DimensionMismatchException(vals.length, dim);
|
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) *
|
FastMath.pow(covarianceMatrixDeterminant, -0.5) *
|
||||||
getExponentTerm(vals);
|
getExponentTerm(vals);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ package org.apache.commons.math3.distribution;
|
||||||
import org.apache.commons.math3.stat.correlation.Covariance;
|
import org.apache.commons.math3.stat.correlation.Covariance;
|
||||||
import org.apache.commons.math3.linear.RealMatrix;
|
import org.apache.commons.math3.linear.RealMatrix;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -130,4 +131,24 @@ public class MultivariateNormalDistributionTest {
|
||||||
Assert.assertEquals(correctDensities[i], densities[i], 1e-16);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue