The utils module

The utils module contains a variety of functions useful to the different classes of the package.

_utils.utils.compute_NN_PBC(X, maxk, box_size=None, p=2, cutoff=inf)[source]

Compute the neighbours of each point taking into account periodic boundaries conditions and eventual cutoff

Parameters:
  • X (np.ndarray) – array of dimension N x D

  • maxk (int) – number of neighbours to save

  • box_size (float, np.ndarray(float)) – sizes of PBC walls. Single value is interpreted as cubic box.

  • p (int) – Minkowski p-norm used

  • cutoff (float) – set an upper bound to the distances. Over such threshold a np.inf will occur

Returns:
  • dist (np.ndarray(float)) – N x maxk array containing the distances from each point to the first maxk nn

  • ind (np.ndarray(int)) – N x maxk array containing the indices of the neighbours of each point

_utils.utils.compute_all_distances(X, n_jobs=2, metric='euclidean')[source]

Compute the distances among all available points of the dataset X

Parameters:
  • X (np.ndarray) – array of dimension N x D

  • n_jobs (int) – number of cores to use for the computation

  • metric (str) – metric used to compute the distances

Returns:

(np.ndarray (float)) – N x N array containing the distances between the N points

_utils.utils.compute_cross_nn_distances(X_new, X, maxk, metric='euclidean', period=None, n_jobs=None)[source]

Compute distances, up to neighbour maxk, between points of X_new and points of X.

The element distances[i,j] represents the distance between point i in dataset X and its j-th neighbour in dataset X_new, whose index is dist_indices[i,j]

Parameters:
  • X_new (np.array(float)) – dataset from which distances are computed

  • X (np.array(float)) – starting dataset of points, from which distances are computed

  • maxk (int) – number of neighbours to save

  • metric (str) – metric used to compute the distances

  • period (float, np.ndarray(float)) – sizes of PBC walls. Single value is interpreted as cubic box.

Returns:
  • distances (np.ndarray(int)) – N x maxk matrix, indices of the neighbours of each point

  • dist_indices (np.ndarray(float)) – N x maxk matrix, distances of the neighbours of each point

_utils.utils.compute_nn_distances(X, maxk, metric='euclidean', period=None, n_jobs=None)[source]

For each point, compute the distances from its first maxk nearest neighbours

Parameters:
  • X (np.ndarray) – points array of dimension N x D

  • maxk (int) – number of neighbours to save

  • metric (str) – metric used to compute the distances

  • period (float, np.ndarray(float)) – sizes of PBC walls. Single value is interpreted as cubic box.

Returns:
  • distances (np.ndarray(int)) – N x maxk matrix, indices of the neighbours of each point

  • dist_indices (np.ndarray(float)) – N x maxk matrix, distances of the neighbours of each point

_utils.utils.from_all_distances_to_nndistances(pdist_matrix, maxk)[source]

Save the first maxk neighbours starting from the matrix of the distances

Parameters:
  • pdist_matrix (np.ndarray(float)) – N x N matrix of distances

  • maxk (int) – number of neighbours to save

Returns:
  • distances (np.ndarray(float)) – N x maxk matrix, distances of the neighbours of each point

  • dist_indices (np.ndarray(int)) – N x maxk matrix, indices of the neighbours of each point