Oihana PHP Arango

l1Distance.php

Table of Contents

Functions

l1Distance()  : string
Return the L1 (Manhattan / taxicab) distance between two vectors.

Functions

l1Distance()

Return the L1 (Manhattan / taxicab) distance between two vectors.

l1Distance(string|int $x, string|int $y) : string

This helper wraps the ArangoDB AQL function L1_DISTANCE(x, y) which calculates the sum of the absolute differences between the components of two equally-sized numeric vectors. The smaller the value, the closer the vectors are.

Unlike approxNearL2(), this computes the exact distance and does not require (nor benefit from) a vector index.

Example AQL usage:

L1_DISTANCE([1, 2], [4, 6])   // returns 7 (|1-4| + |2-6|)
L1_DISTANCE([0, 0], [0, 0])   // returns 0 (identical vectors)
Parameters
$x : string|int

First input array (vector).

$y : string|int

Second input array (vector).

Tags
example
use function oihana\arango\db\functions\numerics\l1Distance;

$expr = l1Distance('[1, 2]', '[4, 6]');
// Produces: 'L1_DISTANCE([1, 2],[4, 6])'
see
https://docs.arangodb.com/stable/aql/functions/numeric/#l1_distance
l2Distance()

For the Euclidean distance.

since
1.1.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

On this page

Search results