Exemple #1
0
void getAllMIWz(const double *data, const double* vec, double *mi, int m, int n, int bin, int so, int norm, int negateMI){
  double *u = (double*) calloc(bin + so, sizeof(double));
  double *y = (double*) calloc(n, sizeof(double));
  double *wx = (double*) calloc(bin * n, sizeof(double));
  double *wy = (double*) calloc(bin * n, sizeof(double));
  int i, j;
  double e1x, e1y, mix, miy, largerMI;

  knotVector(u, bin, so);
  findWeights(vec, u, wx, n, so, bin, -1, -1);
  e1x = entropy1(wx, n, bin);
  mix = 2*e1x - entropy2(wx, wx, n, bin);

  for(i = 0; i < m; i++){
    for(j = 0; j < n; j++) y[j] = data[i + j * m];
    findWeights(y, u, wy, n, so, bin, -1, -1);
    e1y = entropy1(wy, n, bin);
    mi[i] = (e1x + e1y - entropy2(wx, wy, n, bin));
    if(norm == 1){
      largerMI = mix;
      miy = 2*e1y - entropy2(wy, wy, n, bin);
      if(miy > mix) largerMI = miy;
      if(largerMI == 0) largerMI = 1;
      mi[i] /= largerMI;
    }
    if(negateMI==1 && productMoment(y, vec, n) < 0) mi[i] = -mi[i];
  }

  free(wx);
  free(wy);
  free(u);
  free(y);
}
Exemple #2
0
void mi2vs1R(const double *x, const double *y, const double *z, int *n, int *bin, int *so, double *miOut, int *norm){
  double *u = (double*) calloc(*bin + *so, sizeof(double));
  double *wx = (double*) calloc(*bin * *n, sizeof(double));
  double *wy = (double*) calloc(*bin * *n, sizeof(double));
  double *wz = (double*) calloc(*bin * *n, sizeof(double));
  double *wxy = (double*) calloc(*bin * *bin * *n, sizeof(double));
  double e1xy, e1z, mixy, miz, largermi, mi;

  knotVector(u, *bin, *so);
  findWeights(x, u, wx, *n, *so, *bin, -1, -1);
  findWeights(y, u, wy, *n, *so, *bin, -1, -1);
  findWeights(z, u, wz, *n, *so, *bin, -1, -1);
  combineWeights(wx, wy, wxy, *n, *bin);
  free(wx);
  free(wy);

  e1xy = entropy1(wxy, *n, *bin * *bin);
  e1z = entropy1(wz, *n, *bin);
  mi = (e1xy + e1z - entropy2DiffBins(wxy, wz, *n, *bin * *bin, *bin));
  if(*norm == 1){
    mixy = 2*e1xy - entropy2(wxy, wxy, *n, *bin * *bin);
    miz = 2*e1z - entropy2(wz, wz, *n, *bin);
    largermi = mixy > miz ? mixy : miz;
    if(largermi == 0) largermi = 1;
    mi /= largermi;
  }

  free(wxy);
  free(wz);
  free(u);
  *miOut = mi;  
}
Exemple #3
0
void mi2DiffBins(const double *x, const double *y, int *n, int *binx, int *biny, int *sox, int *soy, double *miOut, int *norm, int *negateMI){
	double *ux = (double*) calloc(*binx + *sox, sizeof(double));
	double *wx = (double*) calloc(*binx * *n, sizeof(double));
	double *uy = (double*) calloc(*biny + *soy, sizeof(double));
	double *wy = (double*) calloc(*biny * *n, sizeof(double));
	double e1x, e1y, mix, miy, largermi, mi;
	
	knotVector(ux, *binx, *sox);
	findWeights(x, ux, wx, *n, *sox, *binx, -1, -1);
	free(ux);
	knotVector(uy, *biny, *soy);
	findWeights(y, uy, wy, *n, *soy, *biny, -1, -1);
	free(uy);
	e1x = entropy1(wx, *n, *binx);
	e1y = entropy1(wy, *n, *biny);
	mi = (e1x + e1y - entropy2DiffBins(wx, wy, *n, *binx, *biny));
	
	if(*norm == 1){
		mix = 2*e1x - entropy2(wx, wx, *n, *binx);
		miy = 2*e1y - entropy2(wy, wy, *n, *biny);
		largermi = mix > miy? mix : miy;
		if(largermi == 0) largermi = 1;
		mi /= largermi;
	}
	if(*negateMI == 1 && productMoment(x, y, *n) < 0) mi = -mi;
	free(wx);
	free(wy);
	*miOut = mi;
}
Exemple #4
0
void mi2R(const double *x, const double *y, int *n, int *bin, int *so, double *miOut, int *norm, int *negateMI){
  double *u = (double*) calloc(*bin + *so, sizeof(double));
  double *wx = (double*) calloc(*bin * *n, sizeof(double));
  double *wy = (double*) calloc(*bin * *n, sizeof(double));
  double e1x, e1y, mix, miy, largerMI, mi;

  knotVector(u, *bin, *so);
  findWeights(x, u, wx, *n, *so, *bin, -1, -1);
  findWeights(y, u, wy, *n, *so, *bin, -1, -1);
  e1x = entropy1(wx, *n, *bin);
  e1y = entropy1(wy, *n, *bin);
  mi = (e1x + e1y - entropy2(wx, wy, *n, *bin));

  if(*norm == 1){
    mix = 2*e1x - entropy2(wx, wx, *n, *bin);
    miy = 2*e1y - entropy2(wy, wy, *n, *bin);
    largerMI = mix > miy ? mix:miy;
    if(largerMI == 0) largerMI = 1;
    mi /= largerMI;
  }
  if(*negateMI == 1 && productMoment(x, y, *n) < 0) mi = -mi;
  free(wx);
  free(wy);
  free(u);
  *miOut = mi;
}
Exemple #5
0
double mi2(const double *x, const double *y, int n, int bin, int so, int norm, int negateMI){
  double *u = (double*) calloc(bin + so, sizeof(double));
  double *wx = (double*) calloc(bin * n, sizeof(double));
  double *wy = (double*) calloc(bin * n, sizeof(double));
  double e1x, e1y, mix, miy, largerMI, mi;

  knotVector(u, bin, so);
  findWeights(x, u, wx, n, so, bin, -1, -1);
  findWeights(y, u, wy, n, so, bin, -1, -1);
  e1x = entropy1(wx, n, bin);
  e1y = entropy1(wy, n, bin);
  mi = (e1x + e1y - entropy2(wx, wy, n, bin));

  if(norm){
    mix = 2*e1x - entropy2(wx, wx, n, bin);
    miy = 2*e1y - entropy2(wy, wy, n, bin);
    largerMI = mix > miy ? mix:miy;
    if(largerMI == 0) largerMI = 1;
    mi /= largerMI;
  }
  if(negateMI && productMoment(x, y, n) < 0) mi = -mi;
  free(wx);
  free(wy);
  free(u);
  return mi;
}
matrix *mi(matrix *m, int n, int k, int g) {
	
	//printf("before mi\n");
	matrix *mi;
	double r[g*((m->rows)-g)];
	
//AM:
	//	mi = new_matrix(m->rows, m->rows);
	mi = new_matrix(g, ((m->rows)-g));
//AM: this is the returned matrix mi: 
	//mi[i][j] is the mi between response vec m[i][] i=0,...,g-1 
	//and predictor vec m[j][] where j=g,...,m->rows 
	
	int *knots;
	knots = (int *)malloc((n + k + 1) * sizeof(int));
	calcKnot(knots, n, k);
	/*int l;
	for (l = 0; l < n + k + 1; ++l)
		printf("%d\n", knots[l]);
	*/
	//printf("before p\n");
	matrix *w;
	w = calcWeights(m, n, k, knots);
//	print_matrix(w);
//	printf("w1: %d, %d\n", w->rows, w->cols);
	//printf("p1: %d, %d\n", p->rows, p->cols);
	//printf("before e\n"); //here
	matrix *e;
	e = entropy(w, m->cols, n);
//	print_matrix(e);
	
	//printf("before e2\n");
	matrix *e2;
	e2 = entropy2(w, m->cols, n, g);
//	print_matrix(e2);
	
	int i,j;

//AM:
	//for (i = 0; i < mi->rows; ++i) {
	for (i = 0; i < g; ++i) {
		for (j = g; j < (m->rows) ; ++j) {
			mi->m[i][j-g] = e->m[i][0] + e->m[j][0] - e2->m[i][j];
//			Rprintf("[i,j,mi] = %d %d %lf\n", i, j, mi->m[i][j]);
		}
	}
	//}
//	print_matrix(mi);
	free(knots);
	free_matrix(w);
	free_matrix(e);
	free_matrix(e2);


	return mi;
	
}
Exemple #7
0
void getAllMI3Wz_R(const double *data, const double* vec1, const double* vec2, double *mi, int *m, int *n, int *bin, int *so, int *norm, int *negateMI){
  double *u = (double*) calloc(*bin + *so, sizeof(double));
  double *y = (double*) calloc(*n, sizeof(double));
  double *wx = (double*) calloc(*bin * *n, sizeof(double));
  double *wy = (double*) calloc(*bin * *n, sizeof(double));
  double *wz = (double*) calloc(*bin * *n, sizeof(double));
  int i, j;
 double e1x, e1y, e1z, e2xy, e2xz, e2yz, e3xyz;

  knotVector(u, *bin, *so);
  findWeights(vec1, u, wx, *n, *so, *bin, -1, -1);
  findWeights(vec2, u, wz, *n, *so, *bin, -1, -1);

  e1x  = entropy1(wx, *n, *bin);
  e1z  = entropy1(wz, *n, *bin);
  e2xz = entropy2(wx, wz, *n, *bin);

	
	//mix = 2*e1x - entropy2(wx, wx, *n, *bin);

  for(i = 0; i < *m; i++){
    for(j = 0; j < *n; j++) y[j] = data[i + j * (*m)];

    findWeights(y, u, wy, *n, *so, *bin, -1, -1);
    e1y = entropy1(wy, *n, *bin);
    e2xy = entropy2(wx, wy, *n, *bin);
    e2yz = entropy2(wy, wz, *n, *bin);
    e3xyz= entropy3(wx, wy, wz, *n, *bin);
    mi[i] = (e1x + e1y +  e1z) - (e2xy+e2xz+e2yz) +  e3xyz;
 
  }

  free(wx);
  free(wy);
  free(wz);
  free(u);
  free(y);

}
Exemple #8
0
void mi3(const double *x, const double *y, const double *z, int *n, int *bin, int *so, double *miOut){

  double *u = (double*) calloc(*bin + *so, sizeof(double));
  double *wx = (double*) calloc(*bin * *n, sizeof(double));
  double *wy = (double*) calloc(*bin * *n, sizeof(double));
  double *wz = (double*) calloc(*bin * *n, sizeof(double));

//  double *wxy = (double*) calloc(*bin * *bin * *n, sizeof(double));
//  double *wxz = (double*) calloc(*bin * *bin * *n, sizeof(double));
//  double *wyz = (double*) calloc(*bin * *bin * *n, sizeof(double));

  knotVector(u, *bin, *so);
  findWeights(x, u, wx, *n, *so, *bin, -1, -1);
  findWeights(y, u, wy, *n, *so, *bin, -1, -1);
  findWeights(z, u, wz, *n, *so, *bin, -1, -1);
//  combineWeights(wx, wy, wxy, *n, *bin);
//  combineWeights(wx, wz, wxz, *n, *bin);
//  combineWeights(wy, wz, wyz, *n, *bin);

 // I(X;Y;Z)= [H(X)+ H(Y) + H(Z] -[H(X,Y) +H(X,Z) +H(Y,Z)] + H(X,Y,Z)
  double e1x, e1y, e1z, e2xy, e2xz, e2yz, e3xyz, mi;

  e1x  = entropy1(wx, *n, *bin);
  e1y  = entropy1(wy, *n, *bin);
  e1z  = entropy1(wz, *n, *bin);
  e2xy = entropy2(wx, wy, *n, *bin);
  e2xz = entropy2(wx, wz, *n, *bin);
  e2yz = entropy2(wy, wz, *n, *bin);
  e3xyz= entropy3(wx, wy, wz, *n, *bin);
  
  mi = (e1x + e1y +  e1z) - (e2xy+e2xz+e2yz) +  e3xyz;

  free(u);
  free(wx);
  free(wy);
  free(wz);
  *miOut = mi;

 }
Exemple #9
0
void entropy2R(const double *x, const double *y, int *n, int *bin, int *so, double *eOut){
  double *u = (double*) calloc(*bin + *so, sizeof(double));
  double *wx = (double*) calloc(*bin * *n, sizeof(double));
  double *wy = (double*) calloc(*bin * *n, sizeof(double));
  double entropy;

  knotVector(u, *bin, *so);
  findWeights(x, u, wx, *n, *so, *bin, -1, -1);
  findWeights(y, u, wy, *n, *so, *bin, -1, -1);
  entropy = entropy2(wx, wy, *n, *bin);

  free(wx);
  free(wy);
  free(u);
  *eOut = entropy;
}
Exemple #10
0
void centropy2R(const double *x, const double *y, int *n, int *bin, int *so, double *ceOut){
  double *u = (double*) calloc(*bin + *so, sizeof(double));
  double *wx = (double*) calloc(*bin * *n, sizeof(double));
  double *wy = (double*) calloc(*bin * *n, sizeof(double));
  double e1y, ce;

  //H(X|Y) = H(X,Y) - H(Y)
  knotVector(u, *bin, *so);
  findWeights(x, u, wx, *n, *so, *bin, -1, -1);
  findWeights(y, u, wy, *n, *so, *bin, -1, -1);
  e1y = entropy1(wy, *n, *bin);
  ce = entropy2(wx, wy, *n, *bin) - e1y;

  free(wx);
  free(wy);
  free(u);
  *ceOut = ce;
}