Simple C implementation of hierarchical agglomerative clustering.
float get_distance(some_t* a, some_t* b, some_extra* opts) {
return abs(a - b);
}
void* get_value(some_t* values, int index) {
return &values[index];
}
int total = 100;
some_t* values[total] = { ... };
hc_cluster_t* clusters = hc_new(values, total, get_value);
hc_link_t* links = hc_link(clusters, get_distance, &extra);
hc_level_t* levels = hc_cluster(clusters, links, total);
Create a new hc_cluster_t*
array of clusters.
Create a new hc_link_t*
array of links between each input, measured using
the provided hc_distance_function_t
distance function.
Create a new hc_level_t*
array of length - 1
levels for each merged cluster.
Return a void* to a value at the given index
.
This value is used later for the distance callback.
Return a float representing the distance between a
and b
.