Clover coverage report - baseCode - 0.2.5 Coverage timestamp: Tue Apr 12 2005 11:31:58 EDT FRAMES NO FRAMES |
file stats: | LOC: | 92 |  | Methods: | 5
| NCLOC: | 42 |  | Classes: | 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
Source file | Conditionals | Statements | Methods | TOTAL
MatrixRowStats.java | 100% | 100% | 80% | 96.9% |

1 |  |
     package baseCode.math;
2 |  |
3 |  |
     import baseCode.dataStructure.matrix.DenseDoubleMatrix2DNamed;
4 |  |
     import cern.colt.list.DoubleArrayList;
5 |  |
6 |  |
     /**
7 |  |
      * Convenience functions for getting row statistics from matrices.
8 |  |
      * <p>
9 |  |
      * Copyright (c) 2004
10 |  |
      * </p>
11 |  |
      * <p>
12 |  |
      * Institution:: Columbia University
13 |  |
      * </p>
14 |  |
      *
15 |  |
      * @author Paul Pavlidis
16 |  |
      * @version $Id: MatrixRowStats.java,v 1.11 2004/07/27 03:18:58 pavlidis Exp $
17 |  |
      * @todo Have min() and max() throw an EmptyMatrixException -- this exception class does not yet exist and needs to be
18 |  |
      *       defined somewhere.
19 |  |
      */
20 |  |
     public class MatrixRowStats {
21 |  |
22 | 0 |
        private MatrixRowStats() { /* keep us from instantiating this */
23 |  |
        }
24 |  |
25 |  |
        /**
26 |  |
         * Calculates the sum of squares for each row of a matrix
27 |  |
         *
28 |  |
         * @param M DenseDoubleMatrix2DNamed
29 |  |
         * @return DoubleArrayList
30 |  |
         */
31 | 2 |
        public static DoubleArrayList sumOfSquares( DenseDoubleMatrix2DNamed M ) {
32 | 2 |
           DoubleArrayList r = new DoubleArrayList();
33 |  |
34 | 2 |
           for ( int i = 0; i < M.rows(); i++ ) {
35 | 60 |
              DoubleArrayList row = new DoubleArrayList( M.getRow( i ) );
36 | 60 |
              r.add( DescriptiveWithMissing.sumOfSquares( row ) );
37 |  |
           }
38 |  |
39 | 2 |
           return r;
40 |  |
        }
41 |  |
42 |  |
        /**
43 |  |
         * Calculates the means of a matrix's rows.
44 |  |
         *
45 |  |
         * @param M DenseDoubleMatrix2DNamed
46 |  |
         * @return DoubleArrayList
47 |  |
         */
48 | 1 |
        public static DoubleArrayList means( DenseDoubleMatrix2DNamed M ) {
49 | 1 |
           DoubleArrayList r = new DoubleArrayList();
50 | 1 |
           for ( int i = 0; i < M.rows(); i++ ) {
51 | 30 |
              r.add( DescriptiveWithMissing
52 |  |
                    .mean( new DoubleArrayList( M.getRow( i ) ) ) );
53 |  |
           }
54 | 1 |
           return r;
55 |  |
        }
56 |  |
57 |  |
        /**
58 |  |
         * Calculate the sums of a matrix's rows.
59 |  |
         *
60 |  |
         * @param M DenseDoubleMatrix2DNamed
61 |  |
         * @return DoubleArrayList
62 |  |
         * @todo calls new a lot.
63 |  |
         */
64 | 1 |
        public static DoubleArrayList sums( DenseDoubleMatrix2DNamed M ) {
65 | 1 |
           DoubleArrayList r = new DoubleArrayList();
66 | 1 |
           for ( int i = 0; i < M.rows(); i++ ) {
67 | 30 |
              r.add( DescriptiveWithMissing
68 |  |
                    .sum( new DoubleArrayList( M.getRow( i ) ) ) );
69 |  |
           }
70 | 1 |
           return r;
71 |  |
        }
72 |  |
73 |  |
        /**
74 |  |
         * Calculates the sample standard deviation of each row of a matrix
75 |  |
         *
76 |  |
         * @param M DenseDoubleMatrix2DNamed
77 |  |
         * @return DoubleArrayList
78 |  |
         */
79 | 1 |
        public static DoubleArrayList sampleStandardDeviations(
80 |  |
              DenseDoubleMatrix2DNamed M ) {
81 | 1 |
           DoubleArrayList r = new DoubleArrayList();
82 | 1 |
           for ( int i = 0; i < M.rows(); i++ ) {
83 | 30 |
              DoubleArrayList row = new DoubleArrayList( M.getRow( i ) );
84 | 30 |
              double mean = DescriptiveWithMissing.mean( row );
85 | 30 |
              r
86 |  |
                    .add( Math.sqrt( DescriptiveWithMissing.sampleVariance( row,
87 |  |
                          mean ) ) );
88 |  |
           }
89 | 1 |
           return r;
90 |  |
        }
91 |  |
92 |  |
     }