Exemplo n.º 1
0
static void ana_cluster(FILE *out, t_xrama *xr,real **dih,real time[],
			t_topology *top,int nframes,int mult)
{
  t_cluster *cl=NULL,*scl;
  char      *minimum;
  int       i,j,nx;

  /* Number of dihedrals + terminating NULL 
   * this allows for using string routines
   */
  snew(minimum,xr->ndih+1);
  
  for(i=0; (i<nframes); i++) {
    nx=0;
    for(j=0; (j<xr->ndih); j++) {
      minimum[j] = vphi(&xr->dih[j],dih[j][i],
			mult == -1 ? xr->dih[j].mult : mult);
      if (minimum[j] == NOMIN)
	nx++;
    }
    if (nx == 0) {
      if ((scl=search_cluster(cl,minimum)) == NULL)
	add_cluster(&cl,xr->ndih,minimum);
      else
	scl->freq++;
    }
  }
  p_cluster(out,cl);

  sfree(minimum);
}
Exemplo n.º 2
0
bool CLUSTER::one_to_one() {
  //check if there are less or same number of values then number of desired cl.
  int distinct_values = size;
  for (int i = 0; i < size; i++) {
     for (int j = i - 1; j >= 0; j--) {
        if (values[i].loc == values[j].loc) {
	   distinct_values--;
	   break;
        }
     }
  }
  //there are more distinct values then desired # of clusters
  if (distinct_values > k) return false;
  //there are less or equal distinct values then desired # of clusters
  bool distinct;
  for (int i = 0; i < size; i++) {
     distinct = true;
     for (int j = i - 1; j >= 0; j--) {
        if (values[i].loc == values[j].loc) {
	   distinct = false;
           values[i].center = values[j].center;
	   break;
        }
     }
     if (distinct) values[i].center = centers[add_cluster(values[i].loc)];
  } 
  return true;
}
Exemplo n.º 3
0
CLUSTER::CLUSTER(int _size, int _k, float _seed) {
  BREAKING_POINT = 10.0;
  k = _k;
  size = _size;
  csize = 0;
  values = new CVALUE[_size];  //to be filled in by user
  centers = new CCENTER*[_size+1];
  add_cluster(_seed);
  for (int i = 0; i < size; i++) {
    values[i].center = centers[0];
//    cout << i << ": " << values[i].center->loc << endl;
  }
}
Exemplo n.º 4
0
void CLUSTER::cluster_iso() {
  bool ITER = false;
  int ITER_N = 0;
  float LO_Q = (k+1)/2;
  float HI_Q = 2*k;
  //print();
  while (ITER_N++ < MAX_ITER) {
    //cout << "< Updating membership >" << endl;
    update_membership();
    //print();
    //cout << "< Updating clusters >" << endl;
    float AV_DIST = update_clusters();
    //print();
    if (csize < LO_Q || (csize < HI_Q && ITER)) {
      int u = csize;
      //cout << "< Number of clusters: " << csize << " >" << endl;
      for (int v = 0; u-- > 0; v++) {      
	if (centers[v]->deviation > BREAKING_POINT) {
	  if(LO_Q > csize || 
	     (centers[v]->distance > AV_DIST && centers[v]->size > 2*MIN_SIZE)){
            //cout << "splitting " << centers[v]->loc << endl;
            centers[add_cluster(centers[v]->loc + 0.01)]->size = 0;
	    centers[v]->loc -= 0.01;
	    last_action = _split;
	  } else {
	    if (ITER_N > 1) {
	      if (last_action != _lump) {
		last_action = try_lumping();
	      } else {
		if (csize == 0) break; else continue;
	      }
	    } else {
	      last_action = try_lumping();
	    }	
	  }
	}
      }      
    } else {
      last_action = try_lumping();
    }
    ITER = 1 - ITER;
  } 
}
Exemplo n.º 5
0
void CLUSTER::cluster_iso2() {
  if (one_to_one()) return;
  bool ITER = false;
  unsigned int ITER_N = 0;
  float LO_Q = (k+1)/2;
  float HI_Q = 2*k;
  int last = 0;
  //int last_csize = -1;
  //print();
  last_action = _split;
  while (last < 4) {
 //   cout << "LOOP " << ITER_N << endl;
    last_action = _nothing;
    //cout << "< Updating membership >" << endl;
    update_membership();
    //cout << "< Updating clusters >" << endl;
    float AV_DIST = update_clusters();
    //print();
    //print();
    if (csize < HI_Q) {
      int u = csize;
      //cout << "< Number of clusters: " << csize << " >" << endl;
      for (int v = 0; u-- > 0; v++) {      
	if (centers[v]->deviation > BREAKING_POINT) {
//	  if(LO_Q > csize || 
//	     (centers[v]->distance > AV_DIST && centers[v]->size > 2*MIN_SIZE)){
           //cout << "splitting " << centers[v]->loc << " BR " << BREAKING_POINT << endl;
            centers[add_cluster(centers[v]->loc + 0.0001)]->size = 0;
	    centers[v]->loc -= 0.00001;
	    last = 0;
//	  }
	}
      }      
    }
    ITER = 1 - ITER;
    last++;
    if (last == 4 && csize < k) {
      float OBP = BREAKING_POINT;
      float DV = 0;
      //find average deviation and set BREAKING_POINT to it
      for (int v = 0; v < csize; v++) DV += centers[v]->deviation;
      DV /= csize;
      //make a little smaller then average to be able break a single cluster
      BREAKING_POINT = DV-0.0000001;
      //cout << "adjusting BREAKING_POINT " << BREAKING_POINT <<  endl;
      //take another shot _only_ if this is the first time this BP is used
      if (OBP != BREAKING_POINT) last = 0;
      //there are no divisible clusters, quit
      if (DV == 0) last = 4;
    }
    ITER_N++;
//    cout << "turn " << ITER_N << endl;
  } 
  if (csize < k) {
    //divide largest clusters in 2 ?
  }
  if (csize > k) {
    int EXTRA = csize - k;
    while (EXTRA > 0) {
      update_membership();
      update_clusters();
      cluster_insertion_sort();
      float s = ::distance(centers[0]->loc, centers[1]->loc); // * 
		//  (centers[0]->size + centers[1]->size);
      int l = 0;
      for (int v = 1; v < csize-1; v++) {
        float m = ::distance(centers[v]->loc, centers[v+1]->loc);
        if (m  < s) {
          s = m;
	  l = v;
 	}
      }
      EXTRA--;
      centers[l]->loc = (centers[l]->loc + centers[l+1]->loc)/2;
      erase_cluster(l+1);
    }
  }
  update_membership();
  update_clusters();

}