turicreate.toolkits.distances.transformed_dot_product

turicreate.toolkits.distances.transformed_dot_product(x, y)

Compute the “transformed_dot_product” distance between two dictionaries or two lists of equal length. This is a way to transform the dot product of the two inputs—a similarity measure—into a distance measure. Suppose x and y each contain \(d\) variables:

\[D(x, y) = \log\{1 + \exp\{-\sum_i^d x_i y_i\}\}\]

Warning

The ‘dot_product’ distance is deprecated and will be removed in future versions of Turi Create. Please use ‘transformed_dot_product’ distance instead, although note that this is more than a name change; it is a different transformation of the dot product of two vectors. Please see the distances module documentation for more details.

Parameters:
x : dict or list

First input vector.

y : dict or list

Second input vector.

Returns:
out : float

Notes

  • If the input vectors are in dictionary form, keys missing in one of the two dictionaries are assumed to have value 0.
  • Transformed dot product distance is not a metric because the distance from a point to itself is not 0. This means the ball tree cannot be used to compute nearest neighbors based on this distance.

Examples

>>> tc.distances.transformed_dot_product([1, 2, 3], [4, 5, 6])
0.03125
...
>>> tc.distances.transformed_dot_product({'a': 2, 'c': 4}, {'b': 3, 'c': 12})
0.020833333333333332