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:
- Returns:
ridx – Indices of the N closeset points to idx
- Return type:
- __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_metriciseuclidean, ascipy.spatial.cKDTreeinstance ofself.coords. Undefined otherwise.
- property dists#
A distance matrix of all point pairs. If
self.max_distis notNoneandself.dist_metricis set toeuclidean, ascipy.sparse.csr_matrixsparse 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:
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 (
ms1andms2need to have the samemax_distand)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:
- __init__(ms1, ms2)[source]#
- Parameters:
ms1 (MetricSpace)
ms2 (MetricSpace)
Note (
ms1andms2need to have the samemax_distand)distance_metric.
- property dist_metric#
- property max_dist#
- property dists#
A distance matrix of all point pairs. If
self.max_distis notNoneandself.dist_metricis set toeuclidean, ascipy.sparse.csr_matrixsparse matrix is returned.