template<class C>
Calculate covariance matrix.
Definition at line 580 of file Matrix.h. References CxMatrixTem< C >::_nc, CxMatrixTem< C >::_nr, CxMatrixTem< C >::CxVector< C >, and CxMatrixTem< C >::i(). Referenced by CxMatrixTem< C >::klm(). 00581 { 00582 // printf("Calculating the covariance matrix..."); 00583 int i,j,k; 00584 00585 CxMatrixTem<C> COVxy(_nc,_nc, 0.0) ; 00586 00587 mean = CxVector<C>(_nc) ; //means 00588 for (i=0; i<_nc; i++) mean[i] = 0; 00589 00590 for (k=0; k<_nr; k++) 00591 for (i=0; i<_nc; i++) { 00592 mean[i] += (*this)[k][i]; 00593 for (j=i; j<_nc; j++) 00594 COVxy[i][j] += ((*this)[k][i] * (*this)[k][j]) ; 00595 } 00596 00597 for (i=0; i<_nc; i++) mean[i] /= _nr; 00598 00599 for (i=0; i<_nc; i++) 00600 for (j=i; j<_nc; j++) { 00601 COVxy[i][j] = COVxy[i][j]/_nr - mean[i]*mean[j]; 00602 COVxy[j][i] = COVxy[i][j]; 00603 } 00604 00605 // printf("...done\n"); 00606 return COVxy; 00607 }
Here is the call graph for this function:
|