예제 #1
0
파일: JadeR.c 프로젝트: RenatoPoulicer/HR
void Jade(
	    /* Input.  Number of samples  */
	double *B, /* Output. Separating matrix. nbc*nbc */
	double *X, /* Input.  Data set nbc x nbs */
	int nbc,   /* Input.  Number of sensors  */
	int nbs
	)
{
	double threshold_JD = RELATIVE_JD_THRESHOLD / sqrt((double)nbs);
	int rots = 1;
	int i;
	double *Transf = (double *)calloc(nbc*nbc, sizeof(double));
	double *CumTens = (double *)calloc(nbc*nbc*nbc*nbc, sizeof(double));
	if (Transf == NULL || CumTens == NULL) OutOfMemory();
	/*
	printf("teste \n");
	for (i = 0; i < nbc*nbs; i++){
		if (X[i] == X[i]){
			printf("teste %lf", X[i]);
		}
	}*/
	/* Init */
	Message0(2, "Init...\n");
	Identity(B, nbc);

	MeanRemoval(X, nbc, nbs);

	Message0(2, "Whitening...\n");
	ComputeWhitener(Transf, X, nbc, nbs);
	Transform(X, Transf, nbc, nbs);
	Transform(B, Transf, nbc, nbc);

	Message0(2, "Estimating the cumulant tensor...\n");
	EstCumTens(CumTens, X, nbc, nbs);

	Message0(2, "Joint diagonalization...\n");
	rots = JointDiago(CumTens, Transf, nbc, nbc*nbc, threshold_JD);
	MessageI(3, "Total number of plane rotations: %6i.\n", rots);
	MessageF(3, "Size of the total rotation: %10.7e\n", NonIdentity(Transf, nbc));

	Message0(2, "Updating...\n");
	Transform(X, Transf, nbc, nbs);
	Transform(B, Transf, nbc, nbc);

	

	free(Transf);
	free(CumTens);
}
예제 #2
0
파일: JadeR.c 프로젝트: RenatoPoulicer/HR
void Shibbs(double *B, /* Output. Separating matrix. nbc*nbc */
	double *X, /* Input.  Data set nbc x nbs */
	int nbc,   /* Input.  Number of sensors  */
	int nbs    /* Input.  Number of samples  */
	)
{
	double threshold_JD = RELATIVE_JD_THRESHOLD / sqrt((double)nbs);

	int rots = 1;

	double *Transf = (double *)calloc(nbc*nbc, sizeof(double));
	double *CumMats = (double *)calloc(nbc*nbc*nbc, sizeof(double));
	if (Transf == NULL || CumMats == NULL) OutOfMemory();

	/* Init */
	Message0(2, "Init...\n");
	Identity(B, nbc);
	MeanRemoval(X, nbc, nbs);

	Message0(2, "Whitening...\n");
	ComputeWhitener(Transf, X, nbc, nbs);
	Transform(X, Transf, nbc, nbs);
	Transform(B, Transf, nbc, nbc);

	while (rots>0)
	{
		Message0(2, "Computing cumulant matrices...\n");
		EstCumMats(CumMats, X, nbc, nbs);

		Message0(2, "Joint diagonalization...\n");
		rots = JointDiago(CumMats, Transf, nbc, nbc, threshold_JD);
		MessageI(3, "Total number of plane rotations: %6i.\n", rots);
		MessageF(3, "Size of the total rotation: %10.7e\n", NonIdentity(Transf, nbc));

		Message0(2, "Updating...\n");
		Transform(X, Transf, nbc, nbs);
		Transform(B, Transf, nbc, nbc);
	}
	free(Transf);
	free(CumMats);
}
예제 #3
0
파일: JadeR.c 프로젝트: RenatoPoulicer/HR
/* X: nxT, C: nxnxn.  Computes a stack of n cumulant matrices.  */
void EstCumMats(double *C, double *X, int n, int T)
{
	double *x; /* pointer to a data vector in the data matrix  */
	double *tm; /* temp matrix */
	double *R; /* EXX' : WE DO NOT ASSUME WHITE DATA */

	double xk2, xijkk, xij;
	double ust = 1.0 / (float)T;

	int n2 = n*n;
	int n3 = n*n*n;
	int i, j, k, t, kdec, index;

	Message0(3, "Memory allocation and reset...\n");
	tm = (double *)calloc(n*n, sizeof(double));
	R = (double *)calloc(n*n, sizeof(double));

	if (tm == NULL || R == NULL) OutOfMemory();

	for (i = 0; i<n3; i++) C[i] = 0.0;
	for (i = 0; i<n2; i++) R[i] = 0.0;

	Message0(3, "Computing some moments...\n");
	for (t = 0, x = X; t<T; t++, x += n)
	{
		for (i = 0; i<n; i++)   /* External product (and accumulate for the covariance)  */
			for (j = i; j<n; j++) /* We do not set the symmetric parts yet */
			{
				xij = x[i] * x[j];
				tm[i + j*n] = xij;
				R[i + j*n] += xij;
			}

		/* Accumulate */
		for (k = 0; k<n; k++)
		{
			xk2 = tm[k + k*n];       /* x_k^2 */
			kdec = k*n2;            /* pre_computed shift to address the k-th matrx */
			for (i = 0; i<n; i++)
				for (j = i, index = i + i*n; j<n; j++, index += n)
					C[index + kdec] += xk2 * tm[index]; /* filling the lower part is postponed  */
		}
	}


	Message0(3, "From moments to cumulants...\n");
	/* Normalize and symmetrize the 2th-order moments*/
	for (i = 0; i<n; i++)
		for (j = i; j<n; j++)
		{
			xij = ust * R[i + j*n];
			R[i + j*n] = xij;
			R[j + i*n] = xij;
		}

	/* from moments to cumulants and symmetrization */
	for (k = 0, kdec = 0; k<n; k++, kdec += n2)
		for (i = 0; i<n; i++)
			for (j = i; j<n; j++) {
				xijkk
					= ust * C[i + j*n + kdec]       /* normalization */
					- R[i + j*n] * R[k + k*n]   /* cumulant correction */
					- 2.0 * R[i + k*n] * R[j + k*n];
				C[i + j*n + kdec] = xijkk;
				C[j + i*n + kdec] = xijkk;
			}
	free(tm);
	free(R);
}
예제 #4
0
파일: JadeR.c 프로젝트: RenatoPoulicer/HR
/* X: nxT, C: nxnxnxn.  Computes the cumulant tensor.  */
void EstCumTens(double *C, double *X, int n, int T)
{
	int n2 = n*n;
	int n3 = n*n*n;
	int n4 = n*n*n*n;
	int i, j, k, l, t;
	double Cijkl, xi, xij, xijk, *x;
	double ust = 1.0 / (float)T;

	double *R = (double *)calloc(n*n, sizeof(double));
	/* To store Cov(x).  Recomputed: no whiteness assumption here*/
	if (R == NULL) OutOfMemory();

	for (i = 0; i<n4; i++) C[i] = 0.0;
	for (i = 0; i<n2; i++) R[i] = 0.0;

	Message0(3, "Computing 2nd order cumulants...\n");
	/* accumulation */
	for (t = 0, x = X; t<T; t++, x += n)
		for (i = 0; i<n; i++)
			for (j = i; j<n; j++)
				R[i + j*n] += x[i] * x[j];
	/* normalization and symmetrization */
	for (i = 0; i<n; i++)
		for (j = i; j<n; j++) {
			R[i + j*n] = ust * R[i + j*n];
			R[j + i*n] = R[i + j*n];
		}

	Message0(3, "Computing 4th order cumulants...\n");
	/* accumulation */
	for (t = 0, x = X; t<T; t++, x += n)
		for (i = 0; i<n; i++) {
			xi = x[i];
			for (j = i; j<n; j++) {
				xij = xi *x[j];
				for (k = j; k<n; k++) {
					xijk = xij*x[k];
					for (l = k; l<n; l++)
						MC(i, j, k, l) += xijk*x[l];
				}
			}
		}
	/* normalization, mom2cum, and symmetrization */
	for (i = 0; i<n; i++)
		for (j = i; j<n; j++)
			for (k = j; k<n; k++)
				for (l = k; l<n; l++) {
					Cijkl = ust *  MC(i, j, k, l)
						- R[i + j*n] * R[k + l*n]
						- R[i + k*n] * R[j + l*n]
						- R[i + l*n] * R[j + k*n];

					MC(i, j, k, l) = Cijkl; MC(i, j, l, k) = Cijkl; MC(j, i, k, l) = Cijkl; MC(j, i, l, k) = Cijkl; /* ijxx  */
					MC(i, k, j, l) = Cijkl; MC(i, k, l, j) = Cijkl; MC(k, i, j, l) = Cijkl; MC(k, i, l, j) = Cijkl; /* ikxx  */
					MC(i, l, j, k) = Cijkl; MC(i, l, k, j) = Cijkl; MC(l, i, j, k) = Cijkl; MC(l, i, k, j) = Cijkl; /* ilxx  */
					MC(j, k, i, l) = Cijkl; MC(j, k, l, i) = Cijkl; MC(k, j, i, l) = Cijkl; MC(k, j, l, i) = Cijkl; /* jkxx  */
					MC(j, l, i, k) = Cijkl; MC(j, l, k, i) = Cijkl; MC(l, j, i, k) = Cijkl; MC(l, j, k, i) = Cijkl; /* jlxx  */
					MC(k, l, i, j) = Cijkl; MC(k, l, j, i) = Cijkl; MC(l, k, i, j) = Cijkl; MC(l, k, j, i) = Cijkl; /* klxx  */
				}
	free(R);
}
void Jade (
	     double *B, /* Output. Separating matrix. nbc*nbc */
	     double *X, /* Input.  Data set nbc x nbs */
	     int nbc,   /* Input.  Number of sensors  */
	     int nbs    /* Input.  Number of samples  */
	     )
{
  double threshold_JD = RELATIVE_JD_THRESHOLD / sqrt((double)nbs) ;
  int rots = 1 ;
  double *Transf  = (double *) calloc(nbc*nbc,         sizeof(double)) ; 
  double *CumTens = (double *) calloc(nbc*nbc*nbc*nbc, sizeof(double)) ; 
  if ( Transf == NULL || CumTens == NULL ) OutOfMemory() ;

  /* Init */
  Message0(2, "Init...\n") ;
  Identity(B, nbc); 

  MeanRemoval(X, nbc, nbs)  ; 
printf ("mean\n");

  PrintMat (X, nbc, nbs) ;
printf ("\n");

Message0(2, "Whitening...\n") ;	
  ComputeWhitener(Transf, X, nbc, nbs)  ; 
	
  printf ("Whitener:\n");
  PrintMat (Transf, nbc, nbc) ;
printf ("\n");

  Transform (X, Transf,          nbc, nbs) ;
printf ("Trans X\n");
PrintMat (X, nbc, nbs) ;
printf ("\n");

  Transform (B, Transf,          nbc, nbc) ;


  Message0(2, "Estimating the cumulant tensor...\n") ;
  EstCumTens (CumTens, X,      nbc, nbs) ;

  printf ("cum tens \n");
  PrintMat (CumTens, nbc*nbc, nbc*nbc) ;
	printf ("\n");

  Message0(2, "Joint diagonalization...\n") ;
  rots = JointDiago (CumTens, Transf,  nbc, nbc*nbc, threshold_JD) ;
  MessageI(3, "Total number of plane rotations: %6i.\n", rots) ;
  MessageF(3, "Size of the total rotation: %10.7e\n", NonIdentity(Transf,nbc) )  ;
  
  printf ("Trans mat\n");
  PrintMat (Transf, nbc, nbc) ;
  printf ("\n");

  Message0(2, "Updating...\n") ;
  Transform  (X, Transf,        nbc, nbs ) ;
  Transform  (B, Transf,        nbc, nbc ) ;

  printf ("resultant \n");
  PrintMat (X, nbc, nbs) ;
  printf ("\n");

  printf ("estimated mix \n");
  PrintMat (B, nbc, nbc) ;
  printf ("\n");

  free(Transf) ; 
  free(CumTens) ;
}