1   package baseCode.math;
2   
3   import java.io.IOException;
4   
5   import junit.framework.TestCase;
6   import baseCode.dataFilter.AbstractTestFilter;
7   import baseCode.dataStructure.matrix.AbstractNamedDoubleMatrix;
8   import baseCode.dataStructure.matrix.DenseDoubleMatrix2DNamed;
9   import baseCode.io.reader.DoubleMatrixReader;
10  import baseCode.math.MatrixStats;
11  import baseCode.util.RegressionTesting;
12  
13  /***
14   * 
15   *
16   * <hr>
17   * <p>Copyright (c) 2004 Columbia University
18   * @author pavlidis
19   * @version $Id: TestMatrixStats.java,v 1.1 2005/03/17 13:58:41 pavlidis Exp $
20   */
21  public class TestMatrixStats extends TestCase {
22     
23     protected AbstractNamedDoubleMatrix testdata = null;
24     protected AbstractNamedDoubleMatrix testdatahuge = null;
25     /*
26      * @see TestCase#setUp()
27      */
28     protected void setUp() throws Exception {
29        super.setUp();
30        DoubleMatrixReader f = new DoubleMatrixReader();
31  
32        testdata = ( DenseDoubleMatrix2DNamed ) f.read( AbstractTestFilter.class
33              .getResourceAsStream( "/data/testdata.txt" ) );
34        
35     //  testdatahuge = ( DenseDoubleMatrix2DNamed ) f.read( AbstractTestFilter.class
36      //       .getResourceAsStream( "/data/melanoma_and_sarcomaMAS5.txt" ) );
37     }
38  
39     /*
40      * @see TestCase#tearDown()
41      */
42     protected void tearDown() throws Exception {
43        super.tearDown();
44        testdata = null;
45        testdatahuge = null;
46     }
47     
48     public final void testMin() {
49        double expectedReturn = -965.3;
50        double actualReturn = MatrixStats.min( testdata );
51        assertEquals( "return value", expectedReturn, actualReturn, 0.01 );
52     }
53  
54     public final void testMax() {
55        double expectedReturn = 44625.7;
56        double actualReturn = MatrixStats.max( testdata );
57        assertEquals( "return value", expectedReturn, actualReturn, 0.01 );
58     }
59     
60     public final void testCorrelationMatrix() {
61        DenseDoubleMatrix2DNamed actualReturn = MatrixStats.correlationMatrix(testdata);
62        DoubleMatrixReader f = new DoubleMatrixReader();
63        DenseDoubleMatrix2DNamed expectedReturn = null;
64        try {
65           expectedReturn = (DenseDoubleMatrix2DNamed)f.read( AbstractTestFilter.class
66           .getResourceAsStream( "/data/correlation-matrix-testoutput.txt" ) );
67        } catch ( IOException e ) {
68           e.printStackTrace();
69        } 
70        assertEquals( true, RegressionTesting.closeEnough(expectedReturn, actualReturn, 0.001 ));
71     }
72     
73     public final void testRbfNormalize() {
74        MatrixStats.rbfNormalize(testdata, 100);
75        
76    //   System.err.println(testdata);
77        
78    //    assertEquals( true, RegressionTesting.closeEnough(expectedReturn, testdata, 0.001 ));
79     }
80     
81     
82   /***  public final void testCorrelationMatrixHuge() {
83        SparseDoubleMatrix2DNamed actualReturn = MatrixStats.correlationMatrix(testdatahuge, 0.9);
84        DoubleMatrixReader f = new DoubleMatrixReader();
85        DenseDoubleMatrix2DNamed expectedReturn = null;
86        try {
87           expectedReturn = (DenseDoubleMatrix2DNamed)f.read( AbstractTestFilter.class
88           .getResourceAsStream( "/data/correlation-matrix-testoutput.txt" ) );
89        } catch ( IOException e ) {
90           e.printStackTrace();
91        } catch ( OutOfMemoryError e ) {
92           e.printStackTrace();
93        }
94       // assertEquals( true, RegressionTesting.closeEnough(expectedReturn, actualReturn, 0.001 ));
95     }
96     
97  */
98  }