Example #1
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;
}
Example #2
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);
}
Example #3
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;  
}
Example #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;
}
Example #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;
}
Example #6
0
std::vector<double> RS_Spline::knotu(size_t num, size_t order) const{
	if (data.knotslist.size() == num + order) {
		//use custom knot vector
		return data.knotslist;
	}
	std::vector<double> knotVector(num + order, 0.);
	std::iota(knotVector.begin(), knotVector.end(), 0);
	return knotVector;
}
Example #7
0
void findWeightsR(const double *x, int *n, int *bin, int *so, double *wx){

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

  knotVector(u, *bin, *so);
  findWeights(x, u, wx, *n, *so, *bin, -1, -1);

  //free(wx);
  free(u);
}
Example #8
0
/**
 * Generates B-Spline open knot vector with multiplicity
 * equal to the order at the ends.
 */
std::vector<double> RS_Spline::knot(size_t num, size_t order) const{
	if (data.knotslist.size() == num + order) {
		//use custom knot vector
		return data.knotslist;
	}

	std::vector<double> knotVector(num + order, 0.);
	//use uniform knots
	std::iota(knotVector.begin() + order, knotVector.begin() + num + 1, 1);
	std::fill(knotVector.begin() + num + 1, knotVector.end(), knotVector[num]);
	return knotVector;
}
Example #9
0
void entropy1R(const double *x, 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 entropy;

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

  free(wx);
  free(u);
  *eOut = entropy;
}
Example #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;
}
Example #11
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);

}
Example #12
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;

 }