예제 #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);
}
예제 #2
0
파일: matrix.c 프로젝트: pombreda/yael
/* compute the mean and covariance matrix */
void pca_online_cov (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 * (long)d, n);

  float * mumut = fvec_new (d*(long)d);
  fmat_mul_tr (pca->mu, pca->mu, d, d, 1, mumut);
  fvec_sub (pca->cov, mumut, d*(long)d);
  free (mumut);
  
  fvec_mul_by (pca->cov, d * (long)d, n / (double) (n-1));
  assert(fvec_all_finite(pca->cov,d*(long)d));
  pca->n = -pca->n;
}
예제 #3
0
파일: matrix.c 프로젝트: pombreda/yael
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;
}