DistanceMetric
DistanceMetric class
This class provides a uniform interface to fast distance metric functions. The various metrics can be accessed via the get\_metric
class method and the metric string identifier (see below).
Examples
Python Reference (opens in a new tab)
Constructors
constructor()
Signature
new DistanceMetric(opts?: object): DistanceMetric;
Parameters
Name | Type | Description |
---|---|---|
opts? | object | - |
opts.dist? | any | True distance. |
Returns
Defined in: generated/metrics/DistanceMetric.ts:25 (opens in a new tab)
Properties
_isDisposed
boolean
=false
Defined in: generated/metrics/DistanceMetric.ts:23 (opens in a new tab)
_isInitialized
boolean
=false
Defined in: generated/metrics/DistanceMetric.ts:22 (opens in a new tab)
_py
PythonBridge
Defined in: generated/metrics/DistanceMetric.ts:21 (opens in a new tab)
id
string
Defined in: generated/metrics/DistanceMetric.ts:18 (opens in a new tab)
opts
any
Defined in: generated/metrics/DistanceMetric.ts:19 (opens in a new tab)
Accessors
py
Signature
py(): PythonBridge;
Returns
PythonBridge
Defined in: generated/metrics/DistanceMetric.ts:35 (opens in a new tab)
Signature
py(pythonBridge: PythonBridge): void;
Parameters
Name | Type |
---|---|
pythonBridge | PythonBridge |
Returns
void
Defined in: generated/metrics/DistanceMetric.ts:39 (opens in a new tab)
Methods
dispose()
Disposes of the underlying Python resources.
Once dispose()
is called, the instance is no longer usable.
Signature
dispose(): Promise<void>;
Returns
Promise
<void
>
Defined in: generated/metrics/DistanceMetric.ts:88 (opens in a new tab)
dist_to_rdist()
Convert the true distance to the rank-preserving surrogate distance.
The surrogate distance is any measure that yields the same rank as the distance, but is more efficient to compute. For example, the rank-preserving surrogate distance of the Euclidean metric is the squared-euclidean distance.
Signature
dist_to_rdist(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.dist? | any | True distance. |
Returns
Promise
<any
>
Defined in: generated/metrics/DistanceMetric.ts:107 (opens in a new tab)
get_metric()
Get the given distance metric from the string identifier.
See the docstring of DistanceMetric for a list of available metrics.
Signature
get_metric(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.kwargs? | any | additional arguments will be passed to the requested metric |
opts.metric? | string | The distance metric to use |
Returns
Promise
<any
>
Defined in: generated/metrics/DistanceMetric.ts:142 (opens in a new tab)
init()
Initializes the underlying Python resources.
This instance is not usable until the Promise
returned by init()
resolves.
Signature
init(py: PythonBridge): Promise<void>;
Parameters
Name | Type |
---|---|
py | PythonBridge |
Returns
Promise
<void
>
Defined in: generated/metrics/DistanceMetric.ts:48 (opens in a new tab)
pairwise()
Compute the pairwise distances between X and Y
This is a convenience routine for the sake of testing. For many metrics, the utilities in scipy.spatial.distance.cdist and scipy.spatial.distance.pdist will be faster.
Signature
pairwise(opts: object): Promise<ArrayLike[]>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike | Input data. |
opts.Y? | ArrayLike | Input data. If not specified, then Y=X. |
Returns
Promise
<ArrayLike
[]>
Defined in: generated/metrics/DistanceMetric.ts:182 (opens in a new tab)
rdist_to_dist()
Convert the rank-preserving surrogate distance to the distance.
The surrogate distance is any measure that yields the same rank as the distance, but is more efficient to compute. For example, the rank-preserving surrogate distance of the Euclidean metric is the squared-euclidean distance.
Signature
rdist_to_dist(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.rdist? | any | Surrogate distance. |
Returns
Promise
<any
>
Defined in: generated/metrics/DistanceMetric.ts:224 (opens in a new tab)