DistanceMetric
Uniform interface for fast distance metric functions.
The DistanceMetric
class provides a convenient way to compute pairwise distances between samples. It supports various distance metrics, such as Euclidean distance, Manhattan distance, and more.
The pairwise
method can be used to compute pairwise distances between samples in the input arrays. It returns a distance matrix representing the distances between all pairs of samples.
The get\_metric
method allows you to retrieve a specific metric using its string identifier.
Examples
Python Reference (opens in a new tab)
Constructors
constructor()
Signature
new DistanceMetric(opts?: object): DistanceMetric;
Parameters
Name | Type | Description |
---|---|---|
opts? | object | - |
opts.dtype? | any | The data type of the input on which the metric will be applied. This affects the precision of the computed distances. By default, it is set to np.float64 . |
opts.kwargs? | any | Additional keyword arguments that will be passed to the requested metric. These arguments can be used to customize the behavior of the specific metric. |
opts.metric? | string | The string identifier or class name of the desired distance metric. See the documentation of the DistanceMetric class for a list of available metrics. |
Returns
Defined in: generated/metrics/DistanceMetric.ts:29 (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:104 (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.dtype? | any | The data type of the input on which the metric will be applied. This affects the precision of the computed distances. By default, it is set to np.float64 . |
opts.kwargs? | any | Additional keyword arguments that will be passed to the requested metric. These arguments can be used to customize the behavior of the specific metric. |
opts.metric? | string | The string identifier or class name of the desired distance metric. See the documentation of the DistanceMetric class for a list of available metrics. |
Returns
Promise
<any
>
Defined in: generated/metrics/DistanceMetric.ts:123 (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:62 (opens in a new tab)
Properties
_isDisposed
boolean
=false
Defined in: generated/metrics/DistanceMetric.ts:27 (opens in a new tab)
_isInitialized
boolean
=false
Defined in: generated/metrics/DistanceMetric.ts:26 (opens in a new tab)
_py
PythonBridge
Defined in: generated/metrics/DistanceMetric.ts:25 (opens in a new tab)
id
string
Defined in: generated/metrics/DistanceMetric.ts:22 (opens in a new tab)
opts
any
Defined in: generated/metrics/DistanceMetric.ts:23 (opens in a new tab)
Accessors
metric_obj
An instance of the requested distance metric class.
Signature
metric_obj(): Promise<any>;
Returns
Promise
<any
>
Defined in: generated/metrics/DistanceMetric.ts:168 (opens in a new tab)
py
Signature
py(): PythonBridge;
Returns
PythonBridge
Defined in: generated/metrics/DistanceMetric.ts:49 (opens in a new tab)
Signature
py(pythonBridge: PythonBridge): void;
Parameters
Name | Type |
---|---|
pythonBridge | PythonBridge |
Returns
void
Defined in: generated/metrics/DistanceMetric.ts:53 (opens in a new tab)