51 partition::partition(
size_t num_objects) : cluster_ids(num_objects, 0) {
62 for (
size_t object=0;
object <
cluster_ids.size();
object++) {
77 generate(mapping.begin(), mapping.end(),
sequence());
90 static void write(ostream& out,
const cluster_list& clusters,
const vector<object_id> *medoid_ids = NULL) {
93 copy(medoid_ids->begin(), medoid_ids->end(), ostream_iterator<object_id>(out,
" "));
97 for (
unsigned i=0; i < clusters.size(); i++) {
99 const set<object_id>& c = clusters[i];
101 for (set<object_id>::const_iterator obj=c.begin(); obj != c.end(); obj++) {
102 if (medoid_ids && (*medoid_ids)[i] == *obj) {
103 out <<
"[" << *obj <<
"] ";
114 write(out, clusters);
128 for (
size_t i=0; i < c1.size(); i++) {
129 c1_sum2 += c1[i].size() * c1[i].size();
134 for (
size_t i=0; i < c2.size(); i++) {
135 c2_sum2 += c2[i].size() * c2[i].size();
139 size_t c1c2_sum2 = 0;
140 for (
size_t i=0; i < c1.size(); i++) {
141 for (
size_t j=0; j < c2.size(); j++) {
143 set_intersection(c1[i].begin(), c1[i].end(),
144 c2[j].begin(), c2[j].end(),
146 c1c2_sum2 += size * size;
150 return (c1_sum2 + c2_sum2 - (2 * c1c2_sum2)) / (double)(n*n);
174 for (
size_t i=0; i < list.size(); i++) {
175 for (set<object_id>::iterator o=list[i].begin(); o != list[i].end(); o++) {
176 size_t start = (1 << level) * (*o);
177 size_t end = (1 << level) * (*o + 1);
178 for (
size_t ex=start; ex < end; ex++) {
179 expanded[i].insert(ex);
194 if (!first) out <<
" ";
198 out << start <<
"-" << (o-1);
Generator object for a strided sequence of ints.
std::vector< object_id > medoid_ids
Gives the index of the object that is the ith medoid.
Class to represent a partitioning of a data set.
std::vector< std::set< object_id > > cluster_list
Explicit representation of a clustering.
void swap(partition &other)
Fast swap with other patrition objects.
size_t size() const
Total number of objects in the partition.
void sort()
puts medoids in order by their object id, and adjusts cluster_ids accordingly.
std::ostream & operator<<(std::ostream &out, const id_pair< T > &p)
Print out an id_pair as a tuple of its element and its source rank.
virtual ~partition()
Virtual destructor; currently does nothing.
size_t object_id
More descriptive type for object index.
size_t medoid_id
More descriptive type for medoid index.
void expand(cluster_list &list, size_t level)
Expand a cluster_list by l levels.
Dummy output iterator that counts how many times it was assigned to. without actually storing anythin...
indexed_lt_functor< Indexable > indexed_lt(const Indexable &container)
counter_iterator< T > counter(T &ref)
Adaptor for creating type-inferred counters.
void write_members_with_runs(medoid_id m, std::ostream &out)
Write the members of cluster m out to the output stream formatted nicely with hyphenated runs of cons...
void to_cluster_list(cluster_list &list) const
Creates a list of std::sets from the partition info in medoids and cluster_ids.
void invert(std::vector< Index > &vec)
std::vector< medoid_id > cluster_ids
Gives cluster id (index in medoids) for the ith object.
double mirkin_distance(const cluster_list &c1, const cluster_list &c2)
Mirkin distance bt/w two clusterings.
This represents a partitioning of a data set.