commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject svn commit: r1400017 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math3/distribution/ test/java/org/apache/commons/math3/distribution/
Date Fri, 19 Oct 2012 09:55:02 GMT
Author: erans
Date: Fri Oct 19 09:55:01 2012
New Revision: 1400017

URL: http://svn.apache.org/viewvc?rev=1400017&view=rev
Log:
MATH-815
Added method that was missing in the original commit: "getDimensions()",
renamed to "getDimension()".

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/AbstractMultivariateRealDistribution.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/MultivariateNormalDistribution.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/MultivariateRealDistribution.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/MultivariateNormalDistributionTest.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/AbstractMultivariateRealDistribution.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/AbstractMultivariateRealDistribution.java?rev=1400017&r1=1400016&r2=1400017&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/AbstractMultivariateRealDistribution.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/AbstractMultivariateRealDistribution.java
Fri Oct 19 09:55:01 2012
@@ -31,7 +31,7 @@ public abstract class AbstractMultivaria
     /** RNG instance used to generate samples from the distribution. */
     protected final RandomGenerator random;
     /** The number of dimensions or columns in the multivariate distribution. */
-    private final int numDimensions;
+    private final int dimension;
 
     /**
      * @param rng Random number generator.
@@ -40,7 +40,7 @@ public abstract class AbstractMultivaria
     protected AbstractMultivariateRealDistribution(RandomGenerator rng,
                                                    int n) {
         random = rng;
-        numDimensions = n;
+        dimension = n;
     }
 
     /** {@inheritDoc} */
@@ -48,14 +48,9 @@ public abstract class AbstractMultivaria
         random.setSeed(seed);
     }
 
-    /**
-     * Gets the number of dimensions (i.e. the number of random variables) of
-     * the distribution.
-     *
-     * @return the number of dimensions.
-     */
-    public int getDimensions() {
-        return numDimensions;
+    /** {@inheritDoc} */
+    public int getDimension() {
+        return dimension;
     }
 
     /** {@inheritDoc} */
@@ -67,7 +62,7 @@ public abstract class AbstractMultivaria
             throw new NotStrictlyPositiveException(LocalizedFormats.NUMBER_OF_SAMPLES,
                                                    sampleSize);
         }
-        final double[][] out = new double[sampleSize][numDimensions];
+        final double[][] out = new double[sampleSize][dimension];
         for (int i = 0; i < sampleSize; i++) {
             out[i] = sample();
         }

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=1400017&r1=1400016&r2=1400017&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
Fri Oct 19 09:55:01 2012
@@ -175,7 +175,7 @@ public class MultivariateNormalDistribut
 
     /** {@inheritDoc} */
     public double density(final double[] vals) throws DimensionMismatchException {
-        final int dim = getDimensions();
+        final int dim = getDimension();
         if (vals.length != dim) {
             throw new DimensionMismatchException(vals.length, dim);
         }
@@ -192,7 +192,7 @@ public class MultivariateNormalDistribut
      * @return the standard deviations.
      */
     public double[] getStandardDeviations() {
-        final int dim = getDimensions();
+        final int dim = getDimension();
         final double[] std = new double[dim];
         final double[][] s = covarianceMatrix.getData();
         for (int i = 0; i < dim; i++) {
@@ -203,7 +203,7 @@ public class MultivariateNormalDistribut
 
     /** {@inheritDoc} */
     public double[] sample() {
-        final int dim = getDimensions();
+        final int dim = getDimension();
         final double[] normalVals = new double[dim];
 
         for (int i = 0; i < dim; i++) {

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/MultivariateRealDistribution.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/MultivariateRealDistribution.java?rev=1400017&r1=1400016&r2=1400017&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/MultivariateRealDistribution.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/MultivariateRealDistribution.java
Fri Oct 19 09:55:01 2012
@@ -50,6 +50,15 @@ public interface MultivariateRealDistrib
     void reseedRandomGenerator(long seed);
 
     /**
+     * Gets the number of random variables of the distribution.
+     * It is the size of the array returned by the {@link #sample() sample}
+     * method.
+     *
+     * @return the number of variables.
+     */
+    int getDimension();
+
+    /**
      * Generates a random value vector sampled from this distribution.
      *
      * @return a random value vector.
@@ -63,6 +72,8 @@ public interface MultivariateRealDistrib
      * @return an array representing the random samples.
      * @throws org.apache.commons.math3.exception.NotStrictlyPositiveException
      * if {@code sampleSize} is not positive.
+     *
+     * @see #sample()
      */
     double[][] sample(int sampleSize) throws NotStrictlyPositiveException;
 }

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=1400017&r1=1400016&r2=1400017&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
Fri Oct 19 09:55:01 2012
@@ -56,7 +56,7 @@ public class MultivariateNormalDistribut
         final MultivariateNormalDistribution d = new MultivariateNormalDistribution(mu, sigma);
 
         final RealMatrix s = d.getCovariances();
-        final int dim = d.getDimensions();
+        final int dim = d.getDimension();
         for (int i = 0; i < dim; i++) {
             for (int j = 0; j < dim; j++) {
                 Assert.assertEquals(sigma[i][j], s.getEntry(i, j), 0);
@@ -78,7 +78,7 @@ public class MultivariateNormalDistribut
         final int n = 500000;
 
         final double[][] samples = d.sample(n);
-        final int dim = d.getDimensions();
+        final int dim = d.getDimension();
         final double[] sampleMeans = new double[dim];
 
         for (int i = 0; i < samples.length; i++) {



Mime
View raw message