Along the Paraview plugin, several functions have been developed. Those utilities have different purposes:
The visualization requires a little preparation step that aims at creating necessary or optional files. Those files are either required for the visualization, or assist the visualization with additional elements.
The only necessary file is the edge file that indicates the plugin the end-points of the different connectivity edges in the 3d volume.
Additionally, it is possible to create:
The clustering of edges is performed with the kmeans algorithm.
The version of this algorithm currently being in use within the plugin is implemented in a naive way in Python, using a distance function that is specific to the needs of the visualization. Accelerated algorithms exist such as the [Elkan] and that involves a lower number of computations and distance evaluations.
The hierarchical version of the kMeans runs the kMeans at each level of the hierarchy, and has also a complexity similar to the kMeans multiplied by the number of hierarchy levels.
Since the clustering may take some time to converge, a script accessible after the installation of the package in a virtual environment is provided.
[Elkan] | Elkan: Using the triangle inequality to accelerate k-means, ICML‘03 |
This module defines the k-means clustering used for creating clusters of edges and summarized information for the set of edges. The implementation is pure python and is slow, hence the name naive.
convergent
(old_means, new_means)¶Returns True
if the two sets of edges are close enough.
This would indicate that the convergence of the k-means clustering has been reached.
create_flip_map
(distances)¶Compares two arrays column-wise and returns an array of integer indices denoting whether the first or second array contains the smaller value.
Parameters: | distances – a matrix of shape (2, k, n) where k is the number of means and n is the number of edges each mean is compared to |
---|---|
Returns: | an array of integer values of 0, 1 |
distances
(edges, means)¶Computes the distance between two set of edges.
The distance is summing the distance between the end points of two edges, irrespective of the orientation of those edges.
The fixed set is called means
. For each edge returns the index of
the closest mean edge, as well as a boolean value marking whether or not
edge_i has been closer to the flipped or original version of the mean in
question.
fetch_edges
(mean_index, edges, means)¶Returns a matrix containing all edges assigned to a mean_index.
init_centroids
(k, edges)¶Returns k centroids by randomly sampling data points out of a given set of edges, as a matrix of shape (k, n).
Parameters: |
|
---|---|
Returns: | a matrix of k data points from the original edges matrix |
Raises: |
|
kmeans
(k, edges, max_iterations=100, verbose=False, callback=None)¶Returns k-means clustering of a set of edges.
This algorithm clusters the set of edges
in k
clusters, using the metric
given by the distance()
function.
Parameters: |
|
---|---|
Returns: | a 2-uples where the first element is a matrix of shape |
label_elements
(distances)¶reorder_edges
(edges, flip_map)¶Combines an array edges
of datapoints and its flipped copy into a
single array with length equal to the length of the original edges
.
Datapoints are chosen based on a boolean array flip_map
.
Parameters: |
|
---|---|
Returns: | a matrix of shape (n, 6) |
update_centroids
(edges, labels, means, flip_map)¶Returns an updated matrix of means. For each mean, sets it to the mean of all points assigned to it.
Parameters: |
|
---|---|
Returns: | a matrix of shape (k, 1, n), containing the updated means |