Utility Functions

All utility functions are importable from NNSOM.utils:

from NNSOM.utils import preminmax, get_cluster_avg, get_perc_cluster

They are also re-exported at the top level of NNSOM.

Data normalization

preminmax

Normalize input data row-wise to the range [-1, 1].

Topology geometry

calculate_positions

Compute the 2-D hexagonal grid positions of SOM neurons.

distances

Compute shortest-path distances between all pairs of SOM neurons.

normalize_position

Normalize neuron positions to the range [-1, 1] along each axis.

spread_positions

Map normalized neuron positions into data space using a basis.

get_hexagon_shape

Return the vertex offsets for drawing a unit hexagon.

get_edge_shape

Return the vertex offsets for drawing the elongated diamond between two neurons.

Coordinate transforms

cart2pol

Convert Cartesian coordinates to polar coordinates.

pol2cart

Convert polar coordinates to Cartesian coordinates.

rotate_xy

Rotate 2-D coordinates by a given angle.

Cluster data extraction

get_cluster_data

For each cluster, extract the corresponding data points.

get_cluster_array

Return an object array whose elements are per-cluster feature values.

get_cluster_avg

Compute the mean feature value for each cluster.

count_classes_in_cluster

Count occurrences of each class in every cluster.

cal_class_cluster_intersect

Calculate the intersection sizes of each class with each neuron cluster.

Class and label analysis

closest_class_cluster

Return the class of the closest data point in each cluster.

majority_class_cluster

Return the majority class label for each cluster.

get_perc_cluster

Return the percentage of a target class in each cluster.

get_color_labels

Generate a colour label per cluster based on majority class membership.

get_edge_widths

Calculate edge line widths per cluster based on class membership fraction.

Error and misclassification analysis

get_ind_misclassified

Return indices of misclassified samples.

get_perc_misclassified

Compute the percentage of misclassified samples in each cluster.

get_conf_indices

Return TP, TN, FP, FN indices for a given class in a binary sense.

get_dominant_class_error_types

Map each cluster's dominant class to its majority error type.

Miscellaneous

flatten

Recursively flatten a nested list of numbers into a single list.

get_global_min_max

Find the global minimum and maximum in a nested list.

create_buttons

Create labelled matplotlib Button widgets in a sidebar.

calculate_button_positions

Calculate evenly-spaced button positions within a figure sidebar.