Beispiel #1
0
KMPoint KMData::sample_center(double offset) {
  KMPoint *sampled_p = (*points_)[internal::random_int(points_->size())];
  if (offset == 0.) {
    return *sampled_p;
  }
  KMPoint p;
  for (int i = 0; i < dim_; i++) {
    p.push_back((*sampled_p)[i] + internal::random_uniform(-1., 1) * offset);
  }
  return p;
}
Beispiel #2
0
void KMData::sample_centers(KMPointArray *sample, int k, double offset,
                            bool allow_duplicate) {
  clear_points(sample);
  IMP_LOG_VERBOSE("KMData::sample_centers size: " << sample->size()
                                                  << std::endl);
  if (!allow_duplicate) {
    IMP_INTERNAL_CHECK(((unsigned int)k) <= points_->size(),
                       "not enough points to sample from");
  }
  Ints sampled_ind;
  for (int i = 0; i < k; i++) {
    int ri = internal::random_int(points_->size());
    if (!allow_duplicate) {
      bool dup_found;
      do {
        dup_found = false;
        // search for duplicates
        for (int j = 0; j < i; j++) {
          if (sampled_ind[j] == ri) {
            dup_found = true;
            ri = internal::random_int(points_->size());
            break;
          }
        }
      } while (dup_found);
    }
    sampled_ind.push_back(ri);
    KMPoint *p = new KMPoint();
    KMPoint *copied_p = (*points_)[ri];
    for (int j = 0; j < dim_; j++) {
      p->push_back((*copied_p)[j] + internal::random_uniform(-1., 1) * offset);
    }
    sample->push_back(p);
  }
  IMP_LOG_VERBOSE("KMData::sampled centers  : " << std::endl);
  for (int i = 0; i < k; i++) {
    IMP_LOG_WRITE(VERBOSE, print_point(*((*sample)[i])));
  }
  IMP_LOG_VERBOSE("\nKMData::sample_centers end size : " << sample->size()
                                                         << std::endl);
}
Beispiel #3
0
KMPoint KMRectangle::sample() {
  KMPoint p;
  for (unsigned int i = 0; i < lo_.size(); i++)
    p.push_back(internal::random_uniform(lo_[i], hi_[i]));
  return p;
}