//--------------------------------------------------------- bool CTable_PCA::Get_Matrix(CSG_Matrix &Matrix) { int i, j1, j2; Matrix.Create(m_nFeatures, m_nFeatures); Matrix.Set_Zero(); switch( m_Method ) { //----------------------------------------------------- default: case 0: // Correlation matrix: Center and reduce the column vectors. for(j1=0; j1<m_nFeatures; j1++) { Matrix[j1][j1] = 1.0; } for(i=0; i<m_pTable->Get_Count() && Set_Progress(i, m_pTable->Get_Count()); i++) { if( !is_NoData(i) ) { for(j1=0; j1<m_nFeatures-1; j1++) { for(j2=j1+1; j2<m_nFeatures; j2++) { Matrix[j1][j2] += Get_Value(j1, i) * Get_Value(j2, i); } } } } break; //----------------------------------------------------- case 1: // Variance-covariance matrix: Center the column vectors. case 2: // Sums-of-squares-and-cross-products matrix for(i=0; i<m_pTable->Get_Count() && Set_Progress(i, m_pTable->Get_Count()); i++) { if( !is_NoData(i) ) { for(j1=0; j1<m_nFeatures; j1++) { for(j2=j1; j2<m_nFeatures; j2++) { Matrix[j1][j2] += Get_Value(j1, i) * Get_Value(j2, i); } } } } break; } //----------------------------------------------------- for(j1=0; j1<m_nFeatures; j1++) { for(j2=j1; j2<m_nFeatures; j2++) { Matrix[j2][j1] = Matrix[j1][j2]; } } return( true ); }