Exemple #1
0
BOOL
log_log (conn_t * conn, int event, int subtype, config_t * conf)
{
	switch (event) {
	case LOG_EVT_LOG:
		switch (subtype) {
		case LOG_TYPE_CONNECTIONESTABLISHED:
			return log_connection (conn, event, conn->conf);
			break;
		case LOG_TYPE_CONNECTIONCLOSE:
			return log_summary (conn, event, conn->conf);
			break;
		}
		break;
	default:
		log_connection (conn, event, conf);
		log_summary (conn, event, conf);
		break;
	}
	return TRUE;
}
void KMLProxy::run(Particles *initial_centers) {
  IMP_INTERNAL_CHECK(is_init_,"The proxy was not initialized");
  IMP_LOG(VERBOSE,"KMLProxy::run start \n");
  //use the initial centers if provided
  KMPointArray *kmc=nullptr;
  if (initial_centers != nullptr)  {
    IMP_INTERNAL_CHECK(kcenters_ == initial_centers->size(),
    "the number of initial points differs from the number of required"
    <<" centers\n");
    IMP_LOG(VERBOSE,"KMLProxy::run initial centers provided : \n");
    kmc = allocate_points(kcenters_,atts_.size());
    for (unsigned int i=0;i<kcenters_;i++){
      Particle *cen=(*initial_centers)[i];
      for(unsigned int j=0;j<atts_.size();j++) {
        (*(*kmc)[i])[j]=cen->get_value(atts_[j]);
       }
    }
  }
  IMP_LOG(VERBOSE,"KMLProxy::run load initial guess \n");
  //load the initail guess
  KMFilterCenters ctrs(kcenters_, data_, kmc,damp_factor_);

  //apply lloyd search
  IMP_LOG(VERBOSE,"KMLProxy::run load lloyd \n");
  lloyd_alg_ = new KMLocalSearchLloyd(&ctrs,&term_);
  log_header();
  IMP_CHECK_CODE(clock_t start = clock());
  IMP_LOG(VERBOSE,"KMLProxy::run excute lloyd \n");
  lloyd_alg_->execute();
  IMP_LOG(VERBOSE,"KMLProxy::run analyse \n");
  KMFilterCentersResults best_clusters = lloyd_alg_->get_best();
  IMP_CHECK_CODE(Float exec_time = elapsed_time(start));
  // print summary
  IMP_LOG_WRITE(TERSE,log_summary(&best_clusters,exec_time));
  IMP_LOG_WRITE(TERSE,best_clusters.show(IMP_STREAM));
  IMP_INTERNAL_CHECK(kcenters_
                     == (unsigned int) best_clusters.get_number_of_centers(),
             "The final number of centers does not match the requested one");
  IMP_INTERNAL_CHECK (dim_ == (unsigned int) best_clusters.get_dim(),
              "The dimension of the final clusters is wrong");
  //TODO clear the centroids list
  //set the centroids:
  Particle *p;
  IMP_LOG(VERBOSE,"KMLProxy::run load best results \n");
  for (unsigned int ctr_ind = 0; ctr_ind < kcenters_; ctr_ind++) {
    KMPoint *kmp = best_clusters[ctr_ind];
    //create a new particle
    p = new Particle(m_);
    centroids_.push_back(p);
    for (unsigned int att_ind = 0; att_ind < dim_; att_ind++) {
      p->add_attribute(atts_[att_ind],(*kmp)[att_ind],false);
    }
  }
  //set the assignment of particles to centers
  //array of number of all points
  //TODO - return this
  IMP_LOG(VERBOSE,"KMLProxy::run get assignments \n");
  const Ints *close_center = best_clusters.get_assignments();
  IMP_LOG(VERBOSE,"KMLProxy::run get assignments 2\n");
  for (int i=0;i<data_->get_number_of_points();i++) {
    //std::cout<<"ps number i: " << i << " close center : "
    //<< (*close_center)[i] << std::endl;
    assignment_[ps_[i]]=(*close_center)[i];
  }
}