1+ /*
2+ For more information, please see: http://software.sci.utah.edu
3+
4+ The MIT License
5+
6+ Copyright (c) 2015 Scientific Computing and Imaging Institute,
7+ University of Utah.
8+
9+ License for the specific language governing rights and limitations under
10+ Permission is hereby granted, free of charge, to any person obtaining a
11+ copy of this software and associated documentation files (the "Software"),
12+ to deal in the Software without restriction, including without limitation
13+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
14+ and/or sell copies of the Software, and to permit persons to whom the
15+ Software is furnished to do so, subject to the following conditions:
16+
17+ The above copyright notice and this permission notice shall be included
18+ in all copies or substantial portions of the Software.
19+
20+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26+ DEALINGS IN THE SOFTWARE.
27+ */
28+
29+ #include < gtest/gtest.h>
30+
31+ #include < Core/Datatypes/DenseMatrix.h>
32+ #include < Core/Datatypes/MatrixComparison.h>
33+ #include < Testing/Utils/MatrixTestUtilities.h>
34+ #include < Core/Algorithms/Math/ComputePCA.h>
35+
36+ using namespace SCIRun ::Core::Datatypes;
37+ using namespace SCIRun ::Core::Algorithms::Math;
38+ using namespace SCIRun ::TestUtils;
39+
40+
41+ namespace
42+ {
43+ // Matrix for input
44+ DenseMatrixHandle inputMatrix ()
45+ {
46+ int column1 [12 ] = {5 ,4 ,7 ,8 ,10 ,10 ,4 ,6 ,8 ,7 ,9 ,6 };
47+ int column2 [12 ] = {7 ,6 ,9 ,8 ,5 ,7 ,9 ,3 ,4 ,5 ,5 ,9 };
48+
49+ DenseMatrixHandle inputM (boost::make_shared<DenseMatrix>(12 ,2 ));
50+ for (int i = 0 ; i < inputM->rows (); i++){
51+ (*inputM)(i,0 ) = column1[i];
52+ (*inputM)(i,1 ) = column2[i];
53+ }
54+ return inputM;
55+ }
56+
57+ // A after it is centered
58+ DenseMatrixHandle centeredInputMatrix ()
59+ {
60+
61+ double centeredColumn1 [12 ] = {-2.0 ,-3.0 ,-0.0 ,1.0 ,3.0 ,3.0 ,-3.0 ,-1.0 ,1.0 ,-0.0 ,2.0 ,-1.0 };
62+ double centeredColumn2 [12 ] = {0.583333 ,-0.416667 ,2.583333 ,1.583333 ,-1.416667 ,0.583333 ,2.583333 ,-3.416667 ,-2.416667 ,-1.416667 ,-1.416667 ,2.583333 };
63+
64+ DenseMatrixHandle centeredM (boost::make_shared<DenseMatrix>(12 ,2 ));
65+ for (int i = 0 ; i < centeredM->rows (); i++){
66+ (*centeredM)(i,0 ) = centeredColumn1[i];
67+ (*centeredM)(i,1 ) = centeredColumn2[i];
68+ }
69+ return centeredM;
70+
71+ }
72+
73+ // Outputs: U,S,V
74+ DenseMatrixHandle outputU ()
75+ {}
76+ DenseMatrixHandle outputS ()
77+ {}
78+ DenseMatrixHandle outputV ()
79+ {}
80+
81+ }
82+
83+
84+
85+ TEST (ComputePCAtest, CenterData)
86+ {
87+ ComputePCAAlgo algo;
88+
89+ DenseMatrixHandle m1 (inputMatrix ());
90+
91+ auto centered = ComputePCAAlgo::centerData (m1);
92+
93+ auto expected = *centeredInputMatrix ();
94+
95+ for (int i = 0 ; i < centered.rows (); ++i) {
96+ for (int j = 0 ; j < centered.cols (); ++j)
97+ EXPECT_NEAR (expected (i,j), centered (i,j), 1e-5 );
98+ }
99+ }
100+
101+ // TEST(ComputePCAtest, output1)
102+ // {
103+ // ComputePCAAlgorithm algo;
104+ //
105+ // DenseMatrixHandle m1(testMatrix());
106+ // ComputePCAAlgorithm::Outputs result = algo.run(ComputePCAAlgorithm::Inputs(m1),ComputePCAAlgorithm);
107+ //
108+ // }
109+ //
110+ // TEST(ComputePCAtest, output2)
111+ // {
112+ // ComputePCAAlgorithm algo;
113+ //
114+ // DenseMatrixHandle m1(testMatrix());
115+ //
116+ // }
117+ //
118+ // TEST(ComputePCAtest, output3)
119+ // {
120+ // ComputePCAAlgorithm algo;
121+ //
122+ // DenseMatrixHandle m1(testMatrix());
123+ //
124+ // }
0 commit comments