/** * @license * Copyright 2021, JsData. All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ========================================================================== */ import { Tensor } from '../types'; /** * Abstract type of neighbohood distance metrics. */ export interface Metric { /** * Returns the broadcasted distances between a batch of points `X` and another * batch points `Y`. * * @param X One batch of points, where the last axis represents the point * coordinates. The leading axes represent the batch dimensions. * @param Y Other batch of points, where the last axis represents the point * coordinates. The leading axes represent the batch dimensions. * * @returns A broadcasted distance tensor `D`, where `D[..., i, j]` represents * the distance between point `X[..., i, j, k]` and point `Y[..., i, j, k]`. */ tensorDistance(u: Tensor, v: Tensor): Tensor; /** * Returns the distance between two points `u` and `v`. * * @param u The 1st point coordinates. Must have same length as `v`. * @param v The 2nd point coordinates. Must have same length as `u`. * * @return The distance between `u` and `v` according to this * metric. */ distance(u: ArrayLike, v: ArrayLike): number; /** * Returns minimum distance of a point to a bounding box. * * @param pt The point coordinates. Must be half as long as `bBox`. * @param bBox The bounding box bounds, where `bBox[2*i]` is the lower * bound of coordinate `i` and `bBox[2*i+1]` is the upper * bound of coordinate `i`. */ minDistToBBox?(pt: ArrayLike, bBox: ArrayLike): number; /** * Name of the metric. */ name: string; /** * Returns the name of the metric. */ toString(): string; } /** * Returns the Minkowski distance metric with the given power `p`. * It is equivalent to the p-norm of the absolute difference * between two vectors. * * @param p The power/exponent of the Minkowski distance. * @returns `(X,y) => sum[i]( |X[:,i]-y[i]|**p ) ** (1/p)` */ export declare const minkowskiMetric: (p: number) => Metric;