00001 /* 00002 // 00003 // Copyright 1997-2009 Torsten Rohlfing 00004 // 00005 // Copyright 2004-2010 SRI International 00006 // 00007 // This file is part of the Computational Morphometry Toolkit. 00008 // 00009 // http://www.nitrc.org/projects/cmtk/ 00010 // 00011 // The Computational Morphometry Toolkit is free software: you can 00012 // redistribute it and/or modify it under the terms of the GNU General Public 00013 // License as published by the Free Software Foundation, either version 3 of 00014 // the License, or (at your option) any later version. 00015 // 00016 // The Computational Morphometry Toolkit is distributed in the hope that it 00017 // will be useful, but WITHOUT ANY WARRANTY; without even the implied 00018 // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 // GNU General Public License for more details. 00020 // 00021 // You should have received a copy of the GNU General Public License along 00022 // with the Computational Morphometry Toolkit. If not, see 00023 // <http://www.gnu.org/licenses/>. 00024 // 00025 // $Revision: 2398 $ 00026 // 00027 // $LastChangedDate: 2010-10-05 14:54:37 -0700 (Tue, 05 Oct 2010) $ 00028 // 00029 // $LastChangedBy: torstenrohlfing $ 00030 // 00031 */ 00032 00033 #ifndef __cmtkGeneralLinearModel_h_included_ 00034 #define __cmtkGeneralLinearModel_h_included_ 00035 00036 #include <cmtkconfig.h> 00037 00038 #include <Base/cmtkTypedArray.h> 00039 #include <Base/cmtkMatrix.h> 00040 00041 #include <System/cmtkSmartPtr.h> 00042 #include <System/cmtkThreads.h> 00043 00044 #include <vector> 00045 00046 namespace 00047 cmtk 00048 { 00049 00052 00059 class GeneralLinearModel 00060 { 00061 public: 00063 typedef GeneralLinearModel Self; 00064 00066 typedef SmartPointer<Self> SmartPtr; 00067 00072 GeneralLinearModel( const size_t nParameters, const size_t nData, const double* designMatrix ); 00073 00075 ~GeneralLinearModel(); 00076 00081 double GetSingularValue( const size_t n ) const 00082 { 00083 return (*(this->W))[n]; 00084 } 00085 00088 Matrix2D<double>* GetCorrelationMatrix() const; 00089 00097 void FitModel( std::vector<TypedArray::SmartPtr>& y, const bool normalizeParameters = true ); 00098 00100 TypedArray::SmartPtr& GetModel( const size_t n ) 00101 { 00102 return this->Model[n]; 00103 } 00104 00106 double GetNormFactor( const size_t p ) 00107 { 00108 // do not normalize constant part 00109 if ( this->VariableSD[p] > 0 ) 00110 return this->VariableSD[p]; 00111 else 00112 return 1.0; 00113 } 00114 00116 TypedArray::SmartPtr& GetTStat( const size_t n ) 00117 { 00118 return this->TStat[n]; 00119 } 00120 00122 TypedArray::SmartPtr& GetFStat() 00123 { 00124 return this->FStat; 00125 } 00126 00127 private: 00129 void InitResults( const size_t nPixels ); 00130 00132 size_t NParameters; 00133 00135 size_t NData; 00136 00138 Matrix2D<double> DesignMatrix; 00139 00141 Matrix2D<double>* U; 00142 00144 std::vector< Matrix2D<double>* > Up; 00145 00147 Matrix2D<double>* V; 00148 00150 std::vector< Matrix2D<double>* > Vp; 00151 00153 std::vector<double>* W; 00154 00156 std::vector< std::vector<double>* > Wp; 00157 00159 std::vector<double> VariableMean; 00160 00162 std::vector<double> VariableSD; 00163 00165 std::vector<TypedArray::SmartPtr> Model; 00166 00168 std::vector<TypedArray::SmartPtr> TStat; 00169 00171 TypedArray::SmartPtr FStat; 00172 }; 00173 00175 00176 } // namespace cmtk 00177 00178 #endif // #ifndef __cmtkGeneralLinearModel_h_included_