Beispiel #1
0
/* compute the mean, the covariance matrix, and the eigenvectors.
   They are stored in the structure itself  */
void pca_online_complete (struct pca_online_s * pca)
{
  int d = pca->d;
  int n = pca->n;

  fvec_div_by (pca->mu, d, n);
  fvec_div_by (pca->cov, d * d, n);

  float * mumut = fvec_new (d*d);
  fmat_mul_tr (pca->mu, pca->mu, d, d, 1, mumut);
  fvec_sub (pca->cov, mumut, d*d);
  free (mumut);

  assert(fvec_all_finite(pca->cov,d*d));
  pca->eigvec = fmat_new_pca_from_covariance (d, pca->cov, pca->eigval);
}
Beispiel #2
0
float *fmat_new_pca(int d,int n,const float *v, float *singvals) {

  float *cov=fmat_new_covariance(d,n,v,NULL,1);
  
  assert(fvec_all_finite(cov,d*d));
  
  float *evals=singvals;

  if(!singvals) evals=fvec_new(d);
  
  float *ret=fmat_new_pca_from_covariance(d,cov,evals);

  if(!singvals) free(evals);
    
  free(cov);  
  
  return ret;
}