Cool Functions

Cool functions. Cool, because they apply operations on numpy array groups in a vectorized way.

hnne.cool_functions.cool_max(arr, partition)

Efficiently calculate the max of all elements of an array arr of positive reals over a partition u. The number of classes in the partition is implicitly defined from the values of u.

Parameters:
  • arr (Array of dimensions (n, ).)

  • partition (Partition of the data points in the form of an (n, ) array with k different integer values.)

Returns:

group_max

Return type:

A (k, ) array with the values maximized over the k partition values.

hnne.cool_functions.cool_max_radius(data, partition)

Efficiently calculate the maximum norm of the rows of a matrix data over a partition u. The number of classes in the partition is implicitly defined from the values of u.

Parameters:
  • data (Matrix of dimensions (n, f) with n data points of f features each.)

  • partition (Partition of the data points in the form of an (n, ) array with k different integer values.)

Returns:

group_max_radius

Return type:

A (k, ) array with the maximum vector norms over the k partition values.

hnne.cool_functions.cool_mean(data, partition)

Efficiently calculate the mean of all rows of a matrix M over a partition u. The number of classes in the partition is implicitly defined from the values of u.

Parameters:
  • data (Matrix of dimensions (n, f) with n data points of f features each.)

  • partition (Partition of the data points in the form of an (n, ) array with k different integer values.)

Returns:

group_mean

Return type:

A (k, f) matrix with the vectors averaged over the k partition values.

hnne.cool_functions.cool_normalize(data, partition)

Efficiently normalize the rows of a matrix data over a partition u. The number of classes in the partition is implicitly defined from the values of u.

Parameters:
  • data (Matrix of dimensions (n, f) with n data points of f features each.)

  • partition (Partition of the data points in the form of an (n, ) array with k different integer values.)

Returns:

group_normalized

Return type:

A (n, f) matrix of the original data normalized over the k partition classes.

hnne.cool_functions.cool_std(data, means, partition, epsilon=1e-12)

Efficiently calculate the standard deviation of all rows of a matrix data over a partition u. The means of each partition class are passed with the means matrix. The number of classes in the partition is implicitly defined from the values of u.

Parameters:
  • data (Matrix of dimensions (n, f) with n data points of f features each.)

  • means (Matrix of dimensions (n, f) with the means of the data per class. This implies that each mean is) – repeated over the vectors belonging to the same class.

  • partition (Partition of the data points in the form of an (n, ) array with k different integer values.)

  • epsilon (Small constant to ensure that the standard deviation is not 0. This is specific to this codebase.)

Returns:

group_std – the same partition class contain the same values.

Return type:

A (n, f) matrix with the standard deviation vectors over the k partition values. Rows belonging to