MetricSpace - Coordinate representation¶
MetricSpace¶
-
class
skgstat.
MetricSpace
(coords, dist_metric='euclidean', max_dist=None)[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)[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
- Returns
ridx – Indices of the N closeset points to idx
- Return type
-
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
-
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.
-
tree
¶ If self.dist_metric is euclidean, a scipy.spatial.cKDTree instance of self.coords. Undefined otherwise.
-
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
ms1 (MetricSpace) –
ms2 (MetricSpace) –
Note (ms1 and ms2 need to have the same max_dist and) –
distance_metric. –
-
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
- Returns
ridx – Indices of the N closeset points to idx
- Return type
-
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.
-