MetricSpace - Coordinate representation#

MetricSpace#

class skgstat.MetricSpace(coords, dist_metric='euclidean', max_dist=None, dist_metric_kwargs={})[source]#

A MetricSpace represents a point cloud together with a distance metric and possibly a maximum distance. It efficiently provides the distances between each point pair (when shorter than the maximum distance).

Note: If a max_dist is specified a sparse matrix representation is used for the distances, which saves space and calculation time for large datasets, especially where max_dist << the size of the point cloud in space. However, it slows things down for small datasets.

__init__(coords, dist_metric='euclidean', max_dist=None, dist_metric_kwargs={})[source]#

ProbabalisticMetricSpace class

Parameters:
  • coords (numpy.ndarray) – Coordinate array of shape (Npoints, Ndim)

  • dist_metric (str) – Distance metric names as used by scipy.spatial.distance.pdist

  • max_dist (float) – Maximum distance between points after which the distance is considered infinite and not calculated.

find_closest(idx, max_dist=None, N=None)#

find neighbors Find the (N) closest points (in the right set) to the point with index idx (in the left set).

Parameters:
  • idx (int) – Index of the point that the N closest neighbors are searched for.

  • max_dist (float) – Maximum distance at which other points are searched

  • N (int) – Number of points searched.

Returns:

ridx – Indices of the N closeset points to idx

Return type:

numpy.ndarray

__init__(coords, dist_metric='euclidean', max_dist=None, dist_metric_kwargs={})[source]#

ProbabalisticMetricSpace class

Parameters:
  • coords (numpy.ndarray) – Coordinate array of shape (Npoints, Ndim)

  • dist_metric (str) – Distance metric names as used by scipy.spatial.distance.pdist

  • max_dist (float) – Maximum distance between points after which the distance is considered infinite and not calculated.

property tree#

If self.dist_metric is euclidean, a scipy.spatial.cKDTree instance of self.coords. Undefined otherwise.

property dists#

A distance matrix of all point pairs. If self.max_dist is not None and self.dist_metric is set to euclidean, a scipy.sparse.csr_matrix sparse matrix is returned.

diagonal(idx=None)[source]#

Return a diagonal matrix (as per squareform), optionally for a subset of the points

Parameters:

idx (list) – list of indices that the diagonal matrix is calculated for.

Returns:

diagonal – squareform matrix of the subset of coordinates

Return type:

numpy.ndarray

MetricSpacePair#

class skgstat.MetricSpacePair(ms1, ms2)[source]#

A MetricSpacePair represents a set of point clouds (MetricSpaces). It efficiently provides the distances between each point in one point cloud and each point in the other point cloud (when shorter than the maximum distance). The two point clouds are required to have the same distance metric as well as maximum distance.

__init__(ms1, ms2)[source]#
Parameters:
find_closest(idx, max_dist=None, N=None)#

find neighbors Find the (N) closest points (in the right set) to the point with index idx (in the left set).

Parameters:
  • idx (int) – Index of the point that the N closest neighbors are searched for.

  • max_dist (float) – Maximum distance at which other points are searched

  • N (int) – Number of points searched.

Returns:

ridx – Indices of the N closeset points to idx

Return type:

numpy.ndarray

__init__(ms1, ms2)[source]#
Parameters:
property dist_metric#
property max_dist#
property dists#

A distance matrix of all point pairs. If self.max_dist is not None and self.dist_metric is set to euclidean, a scipy.sparse.csr_matrix sparse matrix is returned.