#include <bsta_k_medoid.h>
Public Member Functions | |
bsta_k_medoid (unsigned n_elements, bool verbose=false) | |
~bsta_k_medoid () | |
void | insert_distance (const unsigned i, const unsigned j, double d) |
insert a distance into the array, the entry j, i is automatically added. | |
double | distance (const unsigned i, const unsigned j) const |
The distance between two elements. | |
void | do_clustering (const unsigned k) |
cluster the elements using k medoids. | |
unsigned | k () const |
get number of medoids. | |
unsigned | medoid (const unsigned i) const |
get a medoid. | |
bool | is_medoid (const unsigned i) const |
is an element a medoid?. | |
unsigned | size (const unsigned k) const |
number of elements in cluster k. | |
vcl_vector< unsigned > | elements (const unsigned k) |
the elements in cluster k. | |
bool | in_cluster (const unsigned i, const unsigned k) const |
is an element in cluster k ?. | |
double | medoid_distance (const unsigned i) const |
the distance between an element and its medoid. | |
double | total_distance (const unsigned k) const |
the total distance between elements and the medoid in cluster k. | |
void | print_distance_array (vcl_ostream &str=vcl_cout) |
print distance array (for debugging). | |
Protected Member Functions | |
double | dc (const unsigned i, const unsigned j, const unsigned k) |
avg distance change for element i resulting from swapping medoids, j->k. | |
double | dcm (const unsigned j, const unsigned k) |
avg inter-medoid distance change resulting from swapping medoids, j->k. | |
bool | replace_medoid (const unsigned j, const unsigned k) |
replace medoid k with medoid k in the set of medoids. | |
bool | test_medoid_swap (unsigned &mj, unsigned &mk) |
determine if a swap of j with k leads to a reduction in distance. | |
void | clear_clusters () |
clear the cluster sets. | |
void | form_clusters () |
assign non-medoids to their nearest medoid, forming clusters. | |
Private Attributes | |
bool | verbose_ |
print useful debug messages. | |
unsigned | n_elements_ |
the size of the distance array. | |
vcl_vector< unsigned > | medoids_ |
the k medoids. | |
vcl_vector< vcl_vector < unsigned > > | clusters_ |
The set of elements closest to a given medoid. | |
vbl_array_2d< double > | distance_array_ |
The array of pair-wise distances between elements. |
Definition at line 29 of file bsta_k_medoid.h.
bsta_k_medoid::bsta_k_medoid | ( | unsigned | n_elements, |
bool | verbose = false |
||
) |
Definition at line 9 of file bsta_k_medoid.cxx.
bsta_k_medoid::~bsta_k_medoid | ( | ) | [inline] |
Definition at line 33 of file bsta_k_medoid.h.
void bsta_k_medoid::clear_clusters | ( | ) | [protected] |
clear the cluster sets.
Clear the cluster vectors.
Definition at line 107 of file bsta_k_medoid.cxx.
double bsta_k_medoid::dc | ( | const unsigned | i, |
const unsigned | j, | ||
const unsigned | k | ||
) | [protected] |
avg distance change for element i resulting from swapping medoids, j->k.
Definition at line 67 of file bsta_k_medoid.cxx.
double bsta_k_medoid::dcm | ( | const unsigned | j, |
const unsigned | k | ||
) | [protected] |
avg inter-medoid distance change resulting from swapping medoids, j->k.
Definition at line 82 of file bsta_k_medoid.cxx.
double bsta_k_medoid::distance | ( | const unsigned | i, |
const unsigned | j | ||
) | const [inline] |
The distance between two elements.
Definition at line 41 of file bsta_k_medoid.h.
void bsta_k_medoid::do_clustering | ( | const unsigned | k | ) |
cluster the elements using k medoids.
Definition at line 218 of file bsta_k_medoid.cxx.
vcl_vector<unsigned> bsta_k_medoid::elements | ( | const unsigned | k | ) | [inline] |
the elements in cluster k.
Definition at line 63 of file bsta_k_medoid.h.
void bsta_k_medoid::form_clusters | ( | ) | [protected] |
assign non-medoids to their nearest medoid, forming clusters.
assign non-medoids to clusters.
Definition at line 115 of file bsta_k_medoid.cxx.
bool bsta_k_medoid::in_cluster | ( | const unsigned | i, |
const unsigned | k | ||
) | const |
is an element in cluster k ?.
Definition at line 28 of file bsta_k_medoid.cxx.
void bsta_k_medoid::insert_distance | ( | const unsigned | i, |
const unsigned | j, | ||
double | d | ||
) | [inline] |
insert a distance into the array, the entry j, i is automatically added.
Definition at line 36 of file bsta_k_medoid.h.
bool bsta_k_medoid::is_medoid | ( | const unsigned | i | ) | const |
is an element a medoid?.
Definition at line 19 of file bsta_k_medoid.cxx.
unsigned bsta_k_medoid::k | ( | ) | const [inline] |
get number of medoids.
Definition at line 48 of file bsta_k_medoid.h.
unsigned bsta_k_medoid::medoid | ( | const unsigned | i | ) | const [inline] |
get a medoid.
Definition at line 52 of file bsta_k_medoid.h.
double bsta_k_medoid::medoid_distance | ( | const unsigned | i | ) | const |
the distance between an element and its medoid.
Definition at line 43 of file bsta_k_medoid.cxx.
void bsta_k_medoid::print_distance_array | ( | vcl_ostream & | str = vcl_cout | ) | [inline] |
print distance array (for debugging).
Definition at line 76 of file bsta_k_medoid.h.
bool bsta_k_medoid::replace_medoid | ( | const unsigned | j, |
const unsigned | k | ||
) | [protected] |
replace medoid k with medoid k in the set of medoids.
replace medoid k with medoid j.
Definition at line 142 of file bsta_k_medoid.cxx.
unsigned bsta_k_medoid::size | ( | const unsigned | k | ) | const [inline] |
number of elements in cluster k.
Definition at line 59 of file bsta_k_medoid.h.
bool bsta_k_medoid::test_medoid_swap | ( | unsigned & | mj, |
unsigned & | mk | ||
) | [protected] |
determine if a swap of j with k leads to a reduction in distance.
Returns false if swap is not warranted.
Definition at line 154 of file bsta_k_medoid.cxx.
double bsta_k_medoid::total_distance | ( | const unsigned | k | ) | const |
the total distance between elements and the medoid in cluster k.
Definition at line 54 of file bsta_k_medoid.cxx.
vcl_vector<vcl_vector<unsigned> > bsta_k_medoid::clusters_ [private] |
The set of elements closest to a given medoid.
Definition at line 110 of file bsta_k_medoid.h.
vbl_array_2d<double> bsta_k_medoid::distance_array_ [private] |
The array of pair-wise distances between elements.
Definition at line 113 of file bsta_k_medoid.h.
vcl_vector<unsigned> bsta_k_medoid::medoids_ [private] |
the k medoids.
Definition at line 107 of file bsta_k_medoid.h.
unsigned bsta_k_medoid::n_elements_ [private] |
the size of the distance array.
Definition at line 104 of file bsta_k_medoid.h.
bool bsta_k_medoid::verbose_ [private] |
print useful debug messages.
Definition at line 101 of file bsta_k_medoid.h.