commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r744800 - /commons/proper/math/trunk/src/java/org/apache/commons/math/stat/correlation/Covariance.java
Date Mon, 16 Feb 2009 05:04:58 GMT
Author: psteitz
Date: Mon Feb 16 05:04:57 2009
New Revision: 744800

URL: http://svn.apache.org/viewvc?rev=744800&view=rev
Log:
Changed to persist and expose the number of observations in the source dataset.

Modified:
    commons/proper/math/trunk/src/java/org/apache/commons/math/stat/correlation/Covariance.java

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/stat/correlation/Covariance.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/correlation/Covariance.java?rev=744800&r1=744799&r2=744800&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/stat/correlation/Covariance.java
(original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/stat/correlation/Covariance.java
Mon Feb 16 05:04:57 2009
@@ -26,7 +26,7 @@
  * Computes covariances for pairs of arrays or columns of a matrix.
  * 
  * <p>The constructors that take <code>RealMatrix</code> or 
- * <code>double[][]</code> arguments generate correlation matrices.  The
+ * <code>double[][]</code> arguments generate covariance matrices.  The
  * columns of the input matrices are assumed to represent variable values.</p>
  * 
  * <p>The constructor argument <code>biasCorrected</code> determines whether
or
@@ -34,7 +34,7 @@
  * 
  * <p>Unbiased covariances are given by the formula</p>
  * <code>cov(X, Y) = &Sigma;[(x<sub>i</sub> - E(X))(y<sub>i</sub>
- E(Y))] / (n - 1)</code>
- * where <code>E(x)</code> is the mean of <code>X</code> and <code>E(Y)</code>
+ * where <code>E(X)</code> is the mean of <code>X</code> and <code>E(Y)</code>
  * is the mean of the <code>Y</code> values.
  * 
  * <p>Non-bias-corrected estimates use <code>n</code> in place of <code>n
- 1</code>
@@ -50,9 +50,16 @@
     /**
      * Create an empty covariance matrix.
      */
+    /** Number of observations (length of covariate vectors) */
+    private final int n;
+    
+    /** 
+     * Create a Covariance with no data
+     */
     public Covariance() {
         super();
         covarianceMatrix = null;
+        n = 0;
     }
     
     /**
@@ -105,6 +112,7 @@
      */
     public Covariance(RealMatrix matrix, boolean biasCorrected) {
        checkSufficientData(matrix);
+       n = matrix.getRowDimension();
        covarianceMatrix = computeCovariance(matrix, biasCorrected);
     }
     
@@ -132,6 +140,16 @@
     }
     
     /**
+     * Returns the number of observations (length of covariate vectors)
+     * 
+     * @return number of observations
+     */
+    
+    public int getN() {
+        return n;
+    }
+    
+    /**
      * Create a covariance matrix from a matrix whose columns represent
      * covariates.
      * @param matrix input matrix (must have at least two columns and two rows)



Mime
View raw message