/* W = sqrt(inv(cov(X)))  */
void ComputeWhitener (double *W, double *X, int n, int T)  
{//ok
  double threshold_W  = RELATIVE_W_THRESHOLD /  sqrt((double) T) ;
  double *Cov  = (double *) calloc(n*n,     sizeof(double)) ; 
  double rescale ;
  int i,j ;

  if (Cov == NULL) OutOfMemory() ;

  EstCovMat (Cov, X, n, T) ; 

  printf ("covmat\n");
  PrintMat (Cov, n, n) ;
  printf ("\n");

  Diago (Cov, W, n, threshold_W)  ;

  printf ("diago\n");
  PrintMat (Cov, n, n) ;
  printf ("\n");

  for (i=0; i<n; i++) {
    rescale= 1.0 / sqrt (Cov[i+i*n]) ;
    for (j=0; j< n ; j++) 
      W[i*n+j] = rescale * W[i*n+j] ;
  }
  free(Cov);//done
}
Пример #2
0
/* W = sqrt(inv(cov(X)))  */
void ComputeWhitener(double *W, double *X, int n, int T)
{
	double threshold_W = RELATIVE_W_THRESHOLD / sqrt((double)T);
	double *Cov = (double *)calloc(n*n, sizeof(double));
	double rescale;
	int i, j;

	if (Cov == NULL) OutOfMemory();

	EstCovMat(Cov, X, n, T);

	Diago(Cov, W, n, threshold_W);

	for (i = 0; i<n; i++) {
		rescale = 1.0 / sqrt(Cov[i + i*n]);
		for (j = 0; j< n; j++)
			W[i + j*n] = rescale * W[i + j*n];
	}
	free(Cov);
}