commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r512039 - in /jakarta/commons/proper/math/trunk/src: java/org/apache/commons/math/random/ java/org/apache/commons/math/stat/descriptive/moment/ mantissa/src/org/spaceroots/mantissa/random/ mantissa/tests-src/org/spaceroots/mantissa/random/ ...
Date Mon, 26 Feb 2007 22:22:55 GMT
Author: luc
Date: Mon Feb 26 14:22:53 2007
New Revision: 512039

URL: http://svn.apache.org/viewvc?view=rev&rev=512039
Log:
added support for generation and analysis of random vectors

Added:
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/random/GaussianRandomGenerator.java
      - copied, changed from r511516, jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/random/GaussianRandomGenerator.java
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/random/NormalizedRandomGenerator.java
      - copied, changed from r511516, jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/random/NormalizedRandomGenerator.java
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/random/NotPositiveDefiniteMatrixException.java
      - copied, changed from r511516, jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/random/NotPositiveDefiniteMatrixException.java
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/random/RandomVectorGenerator.java
      - copied, changed from r511516, jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/random/RandomVectorGenerator.java
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/random/UncorrelatedRandomVectorGenerator.java
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/random/UniformRandomGenerator.java
      - copied, changed from r511516, jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/random/UniformRandomGenerator.java
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/moment/VectorialCovariance.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/moment/VectorialMean.java   (with props)
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/random/GaussianRandomGeneratorTest.java
      - copied, changed from r511516, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/GaussianRandomGeneratorTest.java
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/random/UncorrelatedRandomVectorGeneratorTest.java
      - copied, changed from r511516, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/UncorrelatedRandomVectorGeneratorTest.java
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/random/UniformRandomGeneratorTest.java
      - copied, changed from r511516, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/UniformRandomGeneratorTest.java
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/stat/descriptive/moment/VectorialCovarianceTest.java   (with props)
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/stat/descriptive/moment/VectorialMeanTest.java   (with props)
Removed:
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/random/CorrelatedRandomVectorGenerator.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/random/GaussianRandomGenerator.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/random/NormalizedRandomGenerator.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/random/NotPositiveDefiniteMatrixException.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/random/RandomVectorGenerator.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/random/UncorrelatedRandomVectorGenerator.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/random/UniformRandomGenerator.java
    jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/CorrelatedRandomVectorGeneratorTest.java
    jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/GaussianRandomGeneratorTest.java
    jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/UncorrelatedRandomVectorGeneratorTest.java
    jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/UniformRandomGeneratorTest.java
    jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/VectorialSampleStatisticsTest.java

Copied: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/random/GaussianRandomGenerator.java (from r511516, jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/random/GaussianRandomGenerator.java)
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/random/GaussianRandomGenerator.java?view=diff&rev=512039&p1=jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/random/GaussianRandomGenerator.java&r1=511516&p2=jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/random/GaussianRandomGenerator.java&r2=512039
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/random/GaussianRandomGenerator.java (original)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/random/GaussianRandomGenerator.java Mon Feb 26 14:22:53 2007
@@ -15,55 +15,31 @@
 // specific language governing permissions and limitations
 // under the License.
 
-package org.spaceroots.mantissa.random;
-
-import java.util.Random;
-
-/** This class is a gaussian normalized random generator
- * for scalars.
-
- * <p>This class is a simple interface adaptor around the {@link
- * java.util.Random#nextGaussian nextGaussian} method.</p>
-
- * @version $Id: GaussianRandomGenerator.java 1705 2006-09-17 19:57:39Z luc $
- * @author L. Maisonobe
+package org.apache.commons.math.random;
 
+/** This class is a gaussian normalized random generator for scalars.
+ * <p>This class is a simple wrapper around the {@link
+ * RandomGenerator#nextGaussian} method.</p>
+ * @version $Revision:$ $Date$
  */
 
-public class GaussianRandomGenerator
-  implements NormalizedRandomGenerator {
-
-  /** Create a new generator.
-   * The seed of the generator is related to the current time.
-   */
-  public GaussianRandomGenerator() {
-    generator = new Random();
-  }
-
-  /** Creates a new random number generator using a single int seed.
-   * @param seed the initial seed (32 bits integer)
-   */
-  public GaussianRandomGenerator(int seed) {
-    generator = new Random(seed);
-  }
-
-  /** Create a new generator initialized with a single long seed.
-   * @param seed seed for the generator (64 bits integer)
-   */
-  public GaussianRandomGenerator(long seed) {
-    generator = new Random(seed);
-  }
-
-  /** Generate a random scalar with null mean and unit standard deviation.
-   * @return a random scalar with null mean and unit standard deviation
-   */
-  public double nextDouble() {
-    return generator.nextGaussian();
-  }
+public class GaussianRandomGenerator implements NormalizedRandomGenerator {
 
-  /** Underlying generator. */
-  private Random generator;
+    /** Create a new generator.
+     * @param generator underlying random generator to use
+     */
+    public GaussianRandomGenerator(RandomGenerator generator) {
+        this.generator = generator;
+    }
+
+    /** Generate a random scalar with null mean and unit standard deviation.
+     * @return a random scalar with null mean and unit standard deviation
+     */
+    public double nextNormalizedDouble() {
+        return generator.nextGaussian();
+    }
 
-  private static final long serialVersionUID = 5504568059866195697L;
+    /** Underlying generator. */
+    private RandomGenerator generator;
 
 }

Copied: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/random/NormalizedRandomGenerator.java (from r511516, jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/random/NormalizedRandomGenerator.java)
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/random/NormalizedRandomGenerator.java?view=diff&rev=512039&p1=jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/random/NormalizedRandomGenerator.java&r1=511516&p2=jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/random/NormalizedRandomGenerator.java&r2=512039
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/random/NormalizedRandomGenerator.java (original)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/random/NormalizedRandomGenerator.java Mon Feb 26 14:22:53 2007
@@ -15,26 +15,22 @@
 // specific language governing permissions and limitations
 // under the License.
 
-package org.spaceroots.mantissa.random;
-
-import java.io.Serializable;
+package org.apache.commons.math.random;
 
 /** This interface represent a normalized random generator for
  * scalars.
- * Normalized generator should provide null mean and unit standard
- * deviation scalars.
- * @version $Id: NormalizedRandomGenerator.java 1705 2006-09-17 19:57:39Z luc $
- * @author L. Maisonobe
+ * Normalized generator provide null mean and unit standard deviation scalars.
+ * @version $Revision:$ $Date$
  */
-public interface NormalizedRandomGenerator extends Serializable {
+public interface NormalizedRandomGenerator {
 
   /** Generate a random scalar with null mean and unit standard deviation.
    * <p>This method does <strong>not</strong> specify the shape of the
    * distribution, it is the implementing class that provides it. The
    * only contract here is to generate numbers with null mean and unit
    * standard deviation.</p>
-   * @return a random scalar
+   * @return a random scalar with null mean and unit standard deviation
    */
-  public double nextDouble();
+  public double nextNormalizedDouble();
 
 }

Copied: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/random/NotPositiveDefiniteMatrixException.java (from r511516, jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/random/NotPositiveDefiniteMatrixException.java)
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/random/NotPositiveDefiniteMatrixException.java?view=diff&rev=512039&p1=jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/random/NotPositiveDefiniteMatrixException.java&r1=511516&p2=jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/random/NotPositiveDefiniteMatrixException.java&r2=512039
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/random/NotPositiveDefiniteMatrixException.java (original)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/random/NotPositiveDefiniteMatrixException.java Mon Feb 26 14:22:53 2007
@@ -15,36 +15,25 @@
 // specific language governing permissions and limitations
 // under the License.
 
-package org.spaceroots.mantissa.random;
+package org.apache.commons.math.random;
 
-import org.spaceroots.mantissa.MantissaException;
+import org.apache.commons.math.MathException;
 
 /** This class represents exceptions thrown by the correlated random
  * vector generator.
-
- * @version $Id: NotPositiveDefiniteMatrixException.java 1705 2006-09-17 19:57:39Z luc $
- * @author L. Maisonobe
-
+ * @version $Revision:$ $Date$
  */
 
-public class NotPositiveDefiniteMatrixException
-  extends MantissaException {
-
-  /** Simple constructor.
-   * build an exception with a default message.
-   */
-  public NotPositiveDefiniteMatrixException() {
-    super("not positive definite matrix");
-  }
+public class NotPositiveDefiniteMatrixException extends MathException {
 
-  /** Simple constructor.
-   * build an exception with the specified message.
-   * @param message message to use to build the exception
-   */
-  public NotPositiveDefiniteMatrixException(String message) {
-    super(message);
-  }
+    /** Serializable version identifier */
+    private static final long serialVersionUID = 4122929125438624648L;
 
-  private static final long serialVersionUID = -6801349873804445905L;
+    /** Simple constructor.
+     * build an exception with a default message.
+     */
+    public NotPositiveDefiniteMatrixException() {
+        super("not positive definite matrix", new Object[0]);
+    }
 
 }

Copied: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/random/RandomVectorGenerator.java (from r511516, jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/random/RandomVectorGenerator.java)
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/random/RandomVectorGenerator.java?view=diff&rev=512039&p1=jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/random/RandomVectorGenerator.java&r1=511516&p2=jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/random/RandomVectorGenerator.java&r2=512039
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/random/RandomVectorGenerator.java (original)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/random/RandomVectorGenerator.java Mon Feb 26 14:22:53 2007
@@ -15,7 +15,7 @@
 // specific language governing permissions and limitations
 // under the License.
 
-package org.spaceroots.mantissa.random;
+package org.apache.commons.math.random;
 
 /** This interface represent a random generator for whole vectors.
 
@@ -27,10 +27,7 @@
 public interface RandomVectorGenerator {
 
   /** Generate a random vector.
-   * @return a random vector as an array of double. The generator
-   * <em>will</em> reuse the same array for each call, in order to
-   * save the allocation time, so the user should keep a copy by
-   * himself if he needs so.
+   * @return a random vector as an array of double.
    */
   public double[] nextVector();
 

Added: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/random/UncorrelatedRandomVectorGenerator.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/random/UncorrelatedRandomVectorGenerator.java?view=auto&rev=512039
==============================================================================
--- jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/random/UncorrelatedRandomVectorGenerator.java (added)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/random/UncorrelatedRandomVectorGenerator.java Mon Feb 26 14:22:53 2007
@@ -0,0 +1,86 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//   http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.commons.math.random;
+
+import java.util.Arrays;
+
+/** This class allows to generate random vectors with uncorrelated components.
+ * @version $Id:$
+ */
+
+public class UncorrelatedRandomVectorGenerator
+  implements RandomVectorGenerator {
+
+  /** Simple constructor.
+   * <p>Build an uncorrelated random vector generator from
+   * its mean and standard deviation vectors.</p>
+   * @param mean expected mean values for each component
+   * @param standardDeviation standard deviation for each component
+   * @param generator underlying generator for uncorrelated normalized
+   * components
+   */
+  public UncorrelatedRandomVectorGenerator(double[] mean,
+                                           double[] standardDeviation,
+                                           NormalizedRandomGenerator generator) {
+    if (mean.length != standardDeviation.length) {
+      throw new IllegalArgumentException("dimension mismatch");
+    }
+    this.mean              = (double[]) mean.clone();
+    this.standardDeviation = (double[]) standardDeviation.clone();
+    this.generator = generator;
+  }
+
+  /** Simple constructor.
+   * <p>Build a null mean random and unit standard deviation
+   * uncorrelated vector generator</p>
+   * @param dimension dimension of the vectors to generate
+   * @param generator underlying generator for uncorrelated normalized
+   * components
+   */
+  public UncorrelatedRandomVectorGenerator(int dimension,
+                                           NormalizedRandomGenerator generator) {
+    mean              = new double[dimension];
+    standardDeviation = new double[dimension];
+    Arrays.fill(standardDeviation, 1.0);
+    this.generator = generator;
+  }
+
+  /** Generate a correlated random vector.
+   * @return a random vector as a newly built array of double
+   */
+  public double[] nextVector() {
+
+    double[] random = new double[mean.length]; 
+    for (int i = 0; i < random.length; ++i) {
+      random[i] = mean[i] + standardDeviation[i] * generator.nextNormalizedDouble();
+    }
+
+    return random;
+
+  }
+
+  /** Mean vector. */
+  private double[] mean;
+
+  /** Standard deviation vector. */
+  private double[] standardDeviation;
+
+  /** Underlying scalar generator. */
+  private NormalizedRandomGenerator generator;
+
+}

Copied: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/random/UniformRandomGenerator.java (from r511516, jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/random/UniformRandomGenerator.java)
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/random/UniformRandomGenerator.java?view=diff&rev=512039&p1=jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/random/UniformRandomGenerator.java&r1=511516&p2=jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/random/UniformRandomGenerator.java&r2=512039
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/random/UniformRandomGenerator.java (original)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/random/UniformRandomGenerator.java Mon Feb 26 14:22:53 2007
@@ -15,62 +15,36 @@
 // specific language governing permissions and limitations
 // under the License.
 
-package org.spaceroots.mantissa.random;
-
-import java.util.Random;
+package org.apache.commons.math.random;
 
 /** This class implements a normalized uniform random generator.
-
- * <p>Since this is a normalized random generator, it has a null mean
+ * <p>Since it is a normalized random generator, it has a null mean
  * and a unit standard deviation. Being also a uniform
- * generator, it produces numbers in the range [-sqrt(3) ;
- * sqrt(3)].</p>
-
- * @version $Id: UniformRandomGenerator.java 1705 2006-09-17 19:57:39Z luc $
- * @author L. Maisonobe
-
+ * generator, it produces numbers in the range [-&sqrt;(3) ; +&sqrt;(3)].</p>
+ * @version $Revision:$ $Date$
  */
 
-public class UniformRandomGenerator
-  implements NormalizedRandomGenerator {
-
-  /** Create a new generator.
-   * The seed of the generator is related to the current time.
-   */
-  public UniformRandomGenerator() {
-    generator = new Random();
-  }
-
-  /** Creates a new random number generator using a single int seed.
-   * @param seed the initial seed (32 bits integer)
-   */
-  public UniformRandomGenerator(int seed) {
-    generator = new Random(seed);
-  }
-
-  /** Create a new generator initialized with a single long seed.
-   * @param seed seed for the generator (64 bits integer)
-   */
-  public UniformRandomGenerator(long seed) {
-    generator = new Random(seed);
-  }
-
-  /** Generate a random scalar with null mean and unit standard deviation.
-   * <p>The number generated is uniformly distributed between -sqrt(3)
-   * and sqrt(3).</p>
-   * @return a random scalar with null mean and unit standard deviation
-   */
-  public double nextDouble() {
-    return TWOSQRT3 * generator.nextDouble() - SQRT3;
-  }
-
-  /** Underlying generator. */
-  private Random generator;
+public class UniformRandomGenerator implements NormalizedRandomGenerator {
 
-  private static final double SQRT3 = Math.sqrt(3.0);
+    /** Create a new generator.
+     * @param generator underlying random generator to use
+     */
+    public UniformRandomGenerator(RandomGenerator generator) {
+        this.generator = generator;
+    }
+
+    /** Generate a random scalar with null mean and unit standard deviation.
+     * <p>The number generated is uniformly distributed between -&sqrt;(3)
+     * and +&sqrt;(3).</p>
+     * @return a random scalar with null mean and unit standard deviation
+     */
+    public double nextNormalizedDouble() {
+        return SQRT3 * (2 * generator.nextDouble() - 1.0);
+    }
 
-  private static final double TWOSQRT3 = 2.0 * Math.sqrt(3.0);
+    /** Underlying generator. */
+    private RandomGenerator generator;
 
-  private static final long serialVersionUID = -6913329325753217654L;
+    private static final double SQRT3 = Math.sqrt(3.0);
 
 }

Added: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/moment/VectorialCovariance.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/moment/VectorialCovariance.java?view=auto&rev=512039
==============================================================================
--- jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/moment/VectorialCovariance.java (added)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/moment/VectorialCovariance.java Mon Feb 26 14:22:53 2007
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.math.stat.descriptive.moment;
+
+import java.io.Serializable;
+
+import org.apache.commons.math.DimensionMismatchException;
+import org.apache.commons.math.linear.RealMatrix;
+import org.apache.commons.math.linear.RealMatrixImpl;
+
+/**
+ * Returns the covariance matrix of the available vectors.
+ * @version $Revision:$
+ */
+public class VectorialCovariance implements Serializable {
+
+    /** Serializable version identifier */
+    private static final long serialVersionUID = 4118372414238930270L;
+
+    /** Sums for each component. */
+    private double[] sums;
+
+    /** Sums of products for each component. */
+    private double[] productsSums;
+
+    /** Number of vectors in the sample. */
+    private long n;
+
+    /** Constructs a VectorialMean.
+     * @param dimension vectors dimension
+     */
+    public VectorialCovariance(int dimension) {
+        sums         = new double[dimension];
+        productsSums = new double[dimension * (dimension + 1) / 2];
+        n            = 0;
+    }
+
+    /**
+     * Add a new vector to the sample.
+     * @param vector vector to add
+     * @exception DimensionMismatchException if the vector does not have the right dimension
+     */
+    public void increment(double[] v) throws DimensionMismatchException {
+        if (v.length != sums.length) {
+            throw new DimensionMismatchException(v.length, sums.length);
+        }
+        int k = 0;
+        for (int i = 0; i < v.length; ++i) {
+            sums[i] += v[i];
+            for (int j = 0; j <= i; ++j) {
+                productsSums[k++] += v[i] * v[j];
+            }
+        }
+        n++;
+    }
+
+    /**
+     * Get the covariance matrix.
+     * @return covariance matrix
+     */
+    public RealMatrix getResult() {
+
+        int dimension = sums.length;
+        RealMatrixImpl result = new RealMatrixImpl(dimension, dimension);
+
+        if (n > 1) {
+            double[][] resultData = result.getDataRef();
+            double c = 1.0 / (n * (n - 1));
+            int k = 0;
+            for (int i = 0; i < dimension; ++i) {
+                for (int j = 0; j <= i; ++j) {
+                    double e = c * (n * productsSums[k++] - sums[i] * sums[j]);
+                    resultData[i][j] = e;
+                    resultData[j][i] = e;
+                }
+            }
+        }
+
+        return result;
+
+    }
+
+    /**
+     * Get the number of vectors in the sample.
+     * @return number of vectors in the sample
+     */
+    public long getN() {
+        return n;
+    }
+
+}
\ No newline at end of file

Propchange: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/moment/VectorialCovariance.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/moment/VectorialMean.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/moment/VectorialMean.java?view=auto&rev=512039
==============================================================================
--- jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/moment/VectorialMean.java (added)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/moment/VectorialMean.java Mon Feb 26 14:22:53 2007
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.math.stat.descriptive.moment;
+
+import java.io.Serializable;
+
+import org.apache.commons.math.DimensionMismatchException;
+
+/**
+ * Returns the arithmetic mean of the available vectors.
+ * @version $Revision:$
+ */
+public class VectorialMean implements Serializable {
+
+    /** Serializable version identifier */
+    private static final long serialVersionUID = 8223009086481006892L;
+
+    /** Means for each component. */
+    private Mean[] means;
+
+    /** Constructs a VectorialMean.
+     * @param dimension vectors dimension
+     */
+    public VectorialMean(int dimension) {
+        means = new Mean[dimension];
+        for (int i = 0; i < dimension; ++i) {
+            means[i] = new Mean();
+        }
+    }
+
+    /**
+     * Add a new vector to the sample.
+     * @param vector vector to add
+     * @exception DimensionMismatchException if the vector does not have the right dimension
+     */
+    public void increment(double[] v) throws DimensionMismatchException {
+        if (v.length != means.length) {
+            throw new DimensionMismatchException(v.length, means.length);
+        }
+        for (int i = 0; i < v.length; ++i) {
+            means[i].increment(v[i]);
+        }
+    }
+
+    /**
+     * Get the mean vector.
+     * @return mean vector
+     */
+    public double[] getResult() {
+        double[] result = new double[means.length];
+        for (int i = 0; i < result.length; ++i) {
+            result[i] = means[i].getResult();
+        }
+        return result;
+    }
+
+    /**
+     * Get the number of vectors in the sample.
+     * @return number of vectors in the sample
+     */
+    public long getN() {
+        return (means.length == 0) ? 0 : means[0].getN();
+    }
+
+}
\ No newline at end of file

Propchange: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/moment/VectorialMean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/random/GaussianRandomGeneratorTest.java (from r511516, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/GaussianRandomGeneratorTest.java)
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/random/GaussianRandomGeneratorTest.java?view=diff&rev=512039&p1=jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/GaussianRandomGeneratorTest.java&r1=511516&p2=jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/random/GaussianRandomGeneratorTest.java&r2=512039
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/GaussianRandomGeneratorTest.java (original)
+++ jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/random/GaussianRandomGeneratorTest.java Mon Feb 26 14:22:53 2007
@@ -1,43 +1,47 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-// 
-//   http://www.apache.org/licenses/LICENSE-2.0
-// 
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+
+//http://www.apache.org/licenses/LICENSE-2.0
+
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+//KIND, either express or implied.  See the License for the
+//specific language governing permissions and limitations
+//under the License.
 
-package org.spaceroots.mantissa.random;
+package org.apache.commons.math.random;
+
+import org.apache.commons.math.stat.StatUtils;
 
 import junit.framework.*;
 
 public class GaussianRandomGeneratorTest
-  extends TestCase {
+extends TestCase {
+
+    public GaussianRandomGeneratorTest(String name) {
+        super(name);
+    }
+
+    public void testMeanAndStandardDeviation() {
+        RandomGenerator rg = new JDKRandomGenerator();
+        rg.setSeed(17399225432l);
+        GaussianRandomGenerator generator = new GaussianRandomGenerator(rg);
+        double[] sample = new double[10000];
+        for (int i = 0; i < sample.length; ++i) {
+            sample[i] = generator.nextNormalizedDouble();
+        }
+        assertEquals(0.0, StatUtils.mean(sample), 0.012);
+        assertEquals(1.0, StatUtils.variance(sample), 0.01);
+    }
 
-  public GaussianRandomGeneratorTest(String name) {
-    super(name);
-  }
-
-  public void testMeanAndStandardDeviation() {
-    GaussianRandomGenerator generator = new GaussianRandomGenerator(17399225432l);
-    ScalarSampleStatistics sample = new ScalarSampleStatistics();
-    for (int i = 0; i < 10000; ++i) {
-      sample.add(generator.nextDouble());
+    public static Test suite() {
+        return new TestSuite(GaussianRandomGeneratorTest.class);
     }
-    assertEquals(0.0, sample.getMean(), 0.012);
-    assertEquals(1.0, sample.getStandardDeviation(), 0.01);
-  }
-
-  public static Test suite() {
-    return new TestSuite(GaussianRandomGeneratorTest.class);
-  }
 
 }

Copied: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/random/UncorrelatedRandomVectorGeneratorTest.java (from r511516, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/UncorrelatedRandomVectorGeneratorTest.java)
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/random/UncorrelatedRandomVectorGeneratorTest.java?view=diff&rev=512039&p1=jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/UncorrelatedRandomVectorGeneratorTest.java&r1=511516&p2=jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/random/UncorrelatedRandomVectorGeneratorTest.java&r2=512039
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/UncorrelatedRandomVectorGeneratorTest.java (original)
+++ jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/random/UncorrelatedRandomVectorGeneratorTest.java Mon Feb 26 14:22:53 2007
@@ -1,78 +1,86 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-// 
-//   http://www.apache.org/licenses/LICENSE-2.0
-// 
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package org.spaceroots.mantissa.random;
-
-import org.spaceroots.mantissa.linalg.SymetricalMatrix;
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+
+//http://www.apache.org/licenses/LICENSE-2.0
+
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+//KIND, either express or implied.  See the License for the
+//specific language governing permissions and limitations
+//under the License.
+
+package org.apache.commons.math.random;
+
+import org.apache.commons.math.DimensionMismatchException;
+import org.apache.commons.math.linear.RealMatrix;
+import org.apache.commons.math.stat.descriptive.moment.VectorialCovariance;
+import org.apache.commons.math.stat.descriptive.moment.VectorialMean;
 
 import junit.framework.*;
 
 public class UncorrelatedRandomVectorGeneratorTest
-  extends TestCase {
+extends TestCase {
 
-  public UncorrelatedRandomVectorGeneratorTest(String name) {
-    super(name);
-    mean = null;
-    standardDeviation = null;
-    generator = null;
-  }
-
-  public void testMeanAndCorrelation() {
-
-    VectorialSampleStatistics sample = new VectorialSampleStatistics();
-    for (int i = 0; i < 10000; ++i) {
-      sample.add(generator.nextVector());
+    public UncorrelatedRandomVectorGeneratorTest(String name) {
+        super(name);
+        mean = null;
+        standardDeviation = null;
+        generator = null;
     }
 
-    double[] estimatedMean = sample.getMean();
-    double scale;
-    SymetricalMatrix estimatedCorrelation = sample.getCovarianceMatrix(null);
-    for (int i = 0; i < estimatedMean.length; ++i) {
-      assertEquals(mean[i], estimatedMean[i], 0.07);
-      for (int j = 0; j < i; ++j) {
-        scale = standardDeviation[i] * standardDeviation[j];
-        assertEquals(0, estimatedCorrelation.getElement(i, j) / scale, 0.03);
-      }
-      scale = standardDeviation[i] * standardDeviation[i];
-      assertEquals(1, estimatedCorrelation.getElement(i, i) / scale, 0.025);
+    public void testMeanAndCorrelation() throws DimensionMismatchException {
+
+        VectorialMean meanStat = new VectorialMean(mean.length);
+        VectorialCovariance covStat = new VectorialCovariance(mean.length);
+        for (int i = 0; i < 10000; ++i) {
+            double[] v = generator.nextVector();
+            meanStat.increment(v);
+            covStat.increment(v);
+        }
+
+        double[] estimatedMean = meanStat.getResult();
+        double scale;
+        RealMatrix estimatedCorrelation = covStat.getResult();
+        for (int i = 0; i < estimatedMean.length; ++i) {
+            assertEquals(mean[i], estimatedMean[i], 0.07);
+            for (int j = 0; j < i; ++j) {
+                scale = standardDeviation[i] * standardDeviation[j];
+                assertEquals(0, estimatedCorrelation.getEntry(i, j) / scale, 0.03);
+            }
+            scale = standardDeviation[i] * standardDeviation[i];
+            assertEquals(1, estimatedCorrelation.getEntry(i, i) / scale, 0.025);
+        }
+
     }
 
-  }
+    public void setUp() {
+        mean              = new double[] {0.0, 1.0, -3.0, 2.3};
+        standardDeviation = new double[] {1.0, 2.0, 10.0, 0.1};
+        RandomGenerator rg = new JDKRandomGenerator();
+        rg.setSeed(17399225432l);
+        generator =
+            new UncorrelatedRandomVectorGenerator(mean, standardDeviation,
+                    new GaussianRandomGenerator(rg));
+    }
+
+    public void tearDown() {
+        mean = null;
+        standardDeviation = null;
+        generator = null;
+    }
+
+    public static Test suite() {
+        return new TestSuite(UncorrelatedRandomVectorGeneratorTest.class);
+    }
 
-  public void setUp() {
-    mean              = new double[] {0.0, 1.0, -3.0, 2.3};
-    standardDeviation = new double[] {1.0, 2.0, 10.0, 0.1};
-    generator =
-      new UncorrelatedRandomVectorGenerator(mean, standardDeviation,
-                                            new GaussianRandomGenerator(17399225432l));
-  }
-
-  public void tearDown() {
-    mean = null;
-    standardDeviation = null;
-    generator = null;
-  }
-
-  public static Test suite() {
-    return new TestSuite(UncorrelatedRandomVectorGeneratorTest.class);
-  }
-
-  private double[] mean;
-  private double[] standardDeviation;
-  private UncorrelatedRandomVectorGenerator generator;
+    private double[] mean;
+    private double[] standardDeviation;
+    private UncorrelatedRandomVectorGenerator generator;
 
 }

Copied: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/random/UniformRandomGeneratorTest.java (from r511516, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/UniformRandomGeneratorTest.java)
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/random/UniformRandomGeneratorTest.java?view=diff&rev=512039&p1=jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/UniformRandomGeneratorTest.java&r1=511516&p2=jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/random/UniformRandomGeneratorTest.java&r2=512039
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/random/UniformRandomGeneratorTest.java (original)
+++ jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/random/UniformRandomGeneratorTest.java Mon Feb 26 14:22:53 2007
@@ -1,43 +1,47 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-// 
-//   http://www.apache.org/licenses/LICENSE-2.0
-// 
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+
+//http://www.apache.org/licenses/LICENSE-2.0
+
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+//KIND, either express or implied.  See the License for the
+//specific language governing permissions and limitations
+//under the License.
 
-package org.spaceroots.mantissa.random;
+package org.apache.commons.math.random;
+
+import org.apache.commons.math.stat.StatUtils;
 
 import junit.framework.*;
 
 public class UniformRandomGeneratorTest
-  extends TestCase {
+extends TestCase {
+
+    public UniformRandomGeneratorTest(String name) {
+        super(name);
+    }
+
+    public void testMeanAndStandardDeviation() {
+        RandomGenerator rg = new JDKRandomGenerator();
+        rg.setSeed(17399225432l);
+        UniformRandomGenerator generator = new UniformRandomGenerator(rg);
+        double[] sample = new double[10000];
+        for (int i = 0; i < sample.length; ++i) {
+            sample[i] = generator.nextNormalizedDouble();
+        }
+        assertEquals(0.0, StatUtils.mean(sample), 0.07);
+        assertEquals(1.0, StatUtils.variance(sample), 0.02);
+    }
 
-  public UniformRandomGeneratorTest(String name) {
-    super(name);
-  }
-
-  public void testMeanAndStandardDeviation() {
-    UniformRandomGenerator generator = new UniformRandomGenerator(17399225432l);
-    ScalarSampleStatistics sample = new ScalarSampleStatistics();
-    for (int i = 0; i < 1000; ++i) {
-      sample.add(generator.nextDouble());
+    public static Test suite() {
+        return new TestSuite(UniformRandomGeneratorTest.class);
     }
-    assertEquals(0.0, sample.getMean(), 0.07);
-    assertEquals(1.0, sample.getStandardDeviation(), 0.02);
-  }
-
-  public static Test suite() {
-    return new TestSuite(UniformRandomGeneratorTest.class);
-  }
 
 }

Added: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/stat/descriptive/moment/VectorialCovarianceTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/stat/descriptive/moment/VectorialCovarianceTest.java?view=auto&rev=512039
==============================================================================
--- jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/stat/descriptive/moment/VectorialCovarianceTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/stat/descriptive/moment/VectorialCovarianceTest.java Mon Feb 26 14:22:53 2007
@@ -0,0 +1,101 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+
+//http://www.apache.org/licenses/LICENSE-2.0
+
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+//KIND, either express or implied.  See the License for the
+//specific language governing permissions and limitations
+//under the License.
+
+package org.apache.commons.math.stat.descriptive.moment;
+
+import org.apache.commons.math.DimensionMismatchException;
+import org.apache.commons.math.linear.RealMatrix;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class VectorialCovarianceTest
+extends TestCase {
+
+    public VectorialCovarianceTest(String name) {
+        super(name);
+        points = null;
+    }
+
+    public void testMismatch() {
+        try {
+            new VectorialCovariance(8).increment(new double[5]);
+            fail("an exception should have been thrown");
+        } catch (DimensionMismatchException dme) {
+            assertEquals(5, dme.getDimension1());
+            assertEquals(8, dme.getDimension2());
+        } catch (Exception e) {
+            fail("wrong exception type caught: " + e.getClass().getName());
+        }
+    }
+
+    public void testSimplistic() throws DimensionMismatchException {
+        VectorialCovariance stat = new VectorialCovariance(2);
+        stat.increment(new double[] {-1.0,  1.0});
+        stat.increment(new double[] { 1.0, -1.0});
+        RealMatrix c = stat.getResult();
+        assertEquals( 2.0, c.getEntry(0, 0), 1.0e-12);
+        assertEquals(-2.0, c.getEntry(1, 0), 1.0e-12);
+        assertEquals( 2.0, c.getEntry(1, 1), 1.0e-12);
+    }
+
+    public void testBasicStats() throws DimensionMismatchException {
+
+        VectorialCovariance stat = new VectorialCovariance(points[0].length);
+        for (int i = 0; i < points.length; ++i) {
+            stat.increment(points[i]);
+        }
+
+        assertEquals(points.length, stat.getN());
+
+        RealMatrix c = stat.getResult();
+        double[][] refC    = new double[][] {
+                { 8.0470, -1.9195, -3.4445},
+                {-1.9195,  1.0470,  3.2795},
+                {-3.4445,  3.2795, 12.2070}
+        };
+
+        for (int i = 0; i < c.getRowDimension(); ++i) {
+            for (int j = 0; j <= i; ++j) {
+                assertEquals(refC[i][j], c.getEntry(i, j), 1.0e-12);
+            }
+        }
+
+    }
+
+    public void setUp() {
+        points = new double[][] {
+                { 1.2, 2.3,  4.5},
+                {-0.7, 2.3,  5.0},
+                { 3.1, 0.0, -3.1},
+                { 6.0, 1.2,  4.2},
+                {-0.7, 2.3,  5.0}
+        };
+    }
+
+    public void tearDown() {
+        points = null;
+    }
+
+    public static Test suite() {
+        return new TestSuite(VectorialCovarianceTest.class);
+    }
+
+    private double [][] points;
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/stat/descriptive/moment/VectorialCovarianceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/stat/descriptive/moment/VectorialMeanTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/stat/descriptive/moment/VectorialMeanTest.java?view=auto&rev=512039
==============================================================================
--- jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/stat/descriptive/moment/VectorialMeanTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/stat/descriptive/moment/VectorialMeanTest.java Mon Feb 26 14:22:53 2007
@@ -0,0 +1,93 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+
+//http://www.apache.org/licenses/LICENSE-2.0
+
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+//KIND, either express or implied.  See the License for the
+//specific language governing permissions and limitations
+//under the License.
+
+package org.apache.commons.math.stat.descriptive.moment;
+
+import org.apache.commons.math.DimensionMismatchException;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class VectorialMeanTest
+extends TestCase {
+
+    public VectorialMeanTest(String name) {
+        super(name);
+        points = null;
+    }
+
+    public void testMismatch() {
+        try {
+            new VectorialMean(8).increment(new double[5]);
+            fail("an exception should have been thrown");
+        } catch (DimensionMismatchException dme) {
+            assertEquals(5, dme.getDimension1());
+            assertEquals(8, dme.getDimension2());
+        } catch (Exception e) {
+            fail("wrong exception type caught: " + e.getClass().getName());
+        }
+    }
+
+    public void testSimplistic() throws DimensionMismatchException {
+        VectorialMean stat = new VectorialMean(2);
+        stat.increment(new double[] {-1.0,  1.0});
+        stat.increment(new double[] { 1.0, -1.0});
+        double[] mean = stat.getResult();
+        assertEquals(0.0, mean[0], 1.0e-12);
+        assertEquals(0.0, mean[1], 1.0e-12);
+    }
+
+    public void testBasicStats() throws DimensionMismatchException {
+
+        VectorialMean stat = new VectorialMean(points[0].length);
+        for (int i = 0; i < points.length; ++i) {
+            stat.increment(points[i]);
+        }
+
+        assertEquals(points.length, stat.getN());
+
+        double[] mean = stat.getResult();
+        double[]   refMean = new double[] { 1.78, 1.62,  3.12};
+
+        for (int i = 0; i < mean.length; ++i) {
+            assertEquals(refMean[i], mean[i], 1.0e-12);
+        }
+
+    }
+
+    public void setUp() {
+        points = new double[][] {
+                { 1.2, 2.3,  4.5},
+                {-0.7, 2.3,  5.0},
+                { 3.1, 0.0, -3.1},
+                { 6.0, 1.2,  4.2},
+                {-0.7, 2.3,  5.0}
+        };
+    }
+
+    public void tearDown() {
+        points = null;
+    }
+
+    public static Test suite() {
+        return new TestSuite(VectorialMeanTest.class);
+    }
+
+    private double [][] points;
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/stat/descriptive/moment/VectorialMeanTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message